homebridge-plugin-wrapper
Advanced tools
Comparing version 3.0.1 to 3.1.0
58
index.js
@@ -138,5 +138,5 @@ /* jshint -W097 */ | ||
this.___handleCharacteristicPolling = function(accessory, serviceOrUUID, characteristicOrUUID) { | ||
const service = typeof serviceOrUUID === 'string' ? accessory.services.find(s => s.UUID === serviceOrUUID) : serviceOrUUID; | ||
const characteristic = typeof characteristicOrUUID === 'string' ? service.characteristics.find(c => c.UUID === characteristicOrUUID) : characteristicOrUUID; | ||
this.___handleCharacteristicPolling = function(accessory, serviceOrNameOrUUID, characteristicOrNameOrUUID) { | ||
const service = typeof serviceOrNameOrUUID === 'string' ? accessory.services.find(s => s.displayName === serviceOrNameOrUUID || s.UUID === serviceOrNameOrUUID) : serviceOrNameOrUUID; | ||
const characteristic = typeof characteristicOrNameOrUUID === 'string' ? service.characteristics.find(c => c.displayName === characteristicOrNameOrUUID || c.UUID === characteristicOrNameOrUUID) : characteristicOrNameOrUUID; | ||
let pollingInterval; | ||
@@ -150,5 +150,3 @@ if (that.characteristicPollingList && (characteristic.displayName in that.characteristicPollingList)) { | ||
if (pollingInterval) { | ||
const serviceUUID = service.UUID; | ||
const characteristicUUID = characteristic.UUID; | ||
const key = `${accessory.UUID}.${serviceUUID}.${characteristicUUID}`; | ||
const key = `${accessory.UUID}-${accessory.displayName}.${service.UUID}-${service.displayName}-${service.subtype}.${characteristic.UUID}-${characteristic.displayName}`; | ||
//that.logger.debug('POLLING: char=' + characteristic.displayName + ' ; interval= ' + customStringify(pollingInterval)); | ||
@@ -160,9 +158,9 @@ if (that.characteristicPollingTimeouts[key]) { | ||
delete that.characteristicPollingTimeouts[key]; | ||
const service = accessory.services.find(s => s.UUID === serviceUUID); | ||
const characteristic = service.characteristics.find(c => c.UUID === characteristicUUID); | ||
if (!characteristic) { | ||
const currService = accessory.services.find(s => s.UUID === service.UUID && s.displayName === service.displayName && s.subtype === service.subtype); | ||
const currCharacteristic = currService.characteristics.find(c => c.UUID === characteristic.UUID && c.displayName === characteristic.displayName); | ||
if (!currCharacteristic) { | ||
//console.log(`Characteristic not found: ${serviceUUID}/${characteristicUUID} in ${accessory.displayName}`); | ||
return; | ||
} | ||
this.___getAndPollCharacteristic(accessory, service, characteristic, false); | ||
this.___getAndPollCharacteristic(accessory, currService, currCharacteristic, false); | ||
}, pollingInterval); | ||
@@ -175,3 +173,3 @@ } | ||
if (!err) { | ||
const key = `${accessory.UUID}.${service.UUID}.${characteristic.UUID}`; | ||
const key = `${accessory.UUID}-${accessory.displayName}.${service.UUID}-${service.displayName}-${service.subtype}.${characteristic.UUID}-${characteristic.displayName}`; | ||
if (!that.characteristicValues[key] || that.characteristicValues[key].val !== value || isUpdate) { | ||
@@ -209,3 +207,3 @@ // for accessory updates we should check if we need to repost the value | ||
// Check if we already know the accessory, if yes remove all polling timeouts because will be re-registered | ||
if (key.startsWith(accessory.UUID)) { | ||
if (key.startsWith(`${accessory.UUID}-`)) { | ||
clearTimeout(that.characteristicPollingTimeouts[key]); | ||
@@ -229,3 +227,3 @@ delete that.characteristicPollingTimeouts[key]; | ||
const changeEventHandler = (accessory, data) => { | ||
const key = `${accessory.UUID}.${data.service.UUID}.${data.characteristic.UUID}`; | ||
const key = `${accessory.UUID}-${accessory.displayName}.${data.service.UUID}-${data.service.displayName}-${data.service.subtype}.${data.characteristic.UUID}-${data.characteristic.displayName}`; | ||
const now = Date.now(); | ||
@@ -304,26 +302,26 @@ if (that.characteristicValues[key] && that.characteristicValues[key].val === data.newValue && that.characteristicValues[key].ts > now - 2000) { | ||
this.___pollAccessoryService = async function ___pollAccessoryService(accessory, serviceOrUUID, isUpdate) { | ||
if (typeof serviceOrUUID === 'string') { | ||
serviceOrUUID = accessory.getServiceByUUID(serviceOrUUID); | ||
this.___pollAccessoryService = async function ___pollAccessoryService(accessory, serviceOrNameOrUUID, isUpdate) { | ||
if (typeof serviceOrNameOrUUID === 'string') { | ||
serviceOrNameOrUUID = accessory.services.find(s => s.displayName === serviceOrNameOrUUID || s.UUID === serviceOrNameOrUUID); | ||
} | ||
if (!serviceOrUUID) { | ||
if (!serviceOrNameOrUUID) { | ||
return; | ||
} | ||
for (const characteristic of serviceOrUUID.characteristics) { | ||
await this.___getAndPollCharacteristic(accessory, serviceOrUUID, characteristic, isUpdate); | ||
for (const characteristic of serviceOrNameOrUUID.characteristics) { | ||
await this.___getAndPollCharacteristic(accessory, serviceOrNameOrUUID, characteristic, isUpdate); | ||
} | ||
}; | ||
this.___pollAccessoryServiceCharacteristic = async function ___pollAccessoryServiceCharacteristic(accessory, serviceOrUUID, characteristicOrUUID, isUpdate) { | ||
if (typeof serviceOrUUID === 'string') { | ||
serviceOrUUID = accessory.getServiceByUUID(serviceOrUUID); | ||
this.___pollAccessoryServiceCharacteristic = async function ___pollAccessoryServiceCharacteristic(accessory, serviceOrNameOrUUID, characteristicOrNameOrUUID, isUpdate) { | ||
if (typeof serviceOrNameOrUUID === 'string') { | ||
serviceOrNameOrUUID = accessory.services.find(s => s.displayName === serviceOrNameOrUUID || s.UUID === serviceOrNameOrUUID); | ||
} | ||
if (serviceOrUUID && typeof characteristicOrUUID === 'string') { | ||
characteristicOrUUID = serviceOrUUID.characteristics.find(c => c.UUID === characteristicOrUUID); | ||
if (serviceOrNameOrUUID && typeof characteristicOrNameOrUUID === 'string') { | ||
characteristicOrNameOrUUID = serviceOrNameOrUUID.characteristics.find(c => c.displayName === characteristicOrNameOrUUID || c.UUID === characteristicOrNameOrUUID); | ||
} | ||
if (!serviceOrUUID || !characteristicOrUUID) { | ||
if (!serviceOrNameOrUUID || !characteristicOrNameOrUUID) { | ||
return; | ||
} | ||
return this.___getAndPollCharacteristic(accessory, serviceOrUUID, characteristicOrUUID, isUpdate); | ||
return this.___getAndPollCharacteristic(accessory, serviceOrNameOrUUID, characteristicOrNameOrUUID, isUpdate); | ||
}; | ||
@@ -466,8 +464,8 @@ } | ||
HomebridgeWrapper.prototype.pollAccessoryService = async function pollAccessoryService(accessory, serviceOrUUID, isUpdate) { | ||
return this.server.bridgeService.bridge.___pollAccessoryService(accessory, serviceOrUUID, isUpdate); | ||
HomebridgeWrapper.prototype.pollAccessoryService = async function pollAccessoryService(accessory, serviceOrNameOrUUID, isUpdate) { | ||
return this.server.bridgeService.bridge.___pollAccessoryService(accessory, serviceOrNameOrUUID, isUpdate); | ||
}; | ||
HomebridgeWrapper.prototype.pollAccessoryServiceCharacteristic = async function pollAccessoryServiceCharacteristic(accessory, serviceOrUUID, characteristicOrUUID, isUpdate) { | ||
return this.server.bridgeService.bridge.___pollAccessoryServiceCharacteristic(accessory, serviceOrUUID, characteristicOrUUID, isUpdate); | ||
HomebridgeWrapper.prototype.pollAccessoryServiceCharacteristic = async function pollAccessoryServiceCharacteristic(accessory, serviceOrNameOrUUID, characteristicOrNameOrUUID, isUpdate) { | ||
return this.server.bridgeService.bridge.___pollAccessoryServiceCharacteristic(accessory, serviceOrNameOrUUID, characteristicOrNameOrUUID, isUpdate); | ||
}; | ||
@@ -474,0 +472,0 @@ |
{ | ||
"name": "homebridge-plugin-wrapper", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Wrapper for Homebridge and NodeJS-HAP with reduced dependencies that allows to intercept plugin values and also send to them", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -69,2 +69,5 @@ # homebridge-plugin-wrapper | ||
## Changelog | ||
### 3.1.0 (2022-09-14) | ||
* Another adjustment to the management of services and characteristics to make sure always the current objects are used | ||
### 3.0.1 (2022-09-11) | ||
@@ -71,0 +74,0 @@ * Prevent multiple subscribes on accessory change events |
2928623
144
41113