diff --git a/lib/accessory.js b/lib/accessory.js index 38c17e8..f7ad1b7 100644 --- a/lib/accessory.js +++ b/lib/accessory.js @@ -8,7 +8,7 @@ class OccupancySensor { this.network = network this.log = platform.log this.api = platform.api - this.platformAccessories = platform.accessories + this.platformDevices = platform.devices this.interval = platform.interval this.threshold = !config.threshold && config.threshold !== 0 ? platform.threshold : config.threshold this.mac = config.mac ? config.mac.toLowerCase() : null @@ -34,7 +34,7 @@ class OccupancySensor { } this.UUID = this.api.hap.uuid.generate(this.serial) - this.accessory = this.platformAccessories.find(accessory => accessory.UUID === this.UUID) + this.accessory = platform.accessories.find(accessory => accessory.UUID === this.UUID) if (!this.accessory) { this.log(`Creating New ${platform.PLATFORM_NAME} Accessory for ${this.name}`) @@ -60,7 +60,7 @@ class OccupancySensor { .setCharacteristic(Characteristic.SerialNumber, this.serial) if (config.anyone) - this.addAnyoneSensor + this.addAnyoneSensor() else this.addOccupancySensor() @@ -122,15 +122,15 @@ class OccupancySensor { .on('get', (callback) => callback(null, this.isDetected)) .updateValue(this.isDetected) - setInterval(() => { - this.updateAnyone() - }, this.interval) + setInterval(() => { + this.updateAnyone() + }, this.interval) } updateAnyone() { // check if any accessory isDetected ( === 1 ) - const isDetected = this.platformAccessories.find(pAccessory => pAccessory.isDetected) + const isDetected = this.platformDevices.find(pDevice => pDevice.isDetected) if (isDetected && !this.isDetected) { this.log(`[${this.name}] - Someone connected to the network`) this.isDetected = 1 diff --git a/lib/network.js b/lib/network.js index 0d68401..84fb9c6 100644 --- a/lib/network.js +++ b/lib/network.js @@ -17,7 +17,7 @@ const init = function() { this.devicesConfig.forEach(device => this.devices.push(new Accessory(net, device, this))) if (this.anyoneSensor) - this.devices.push(new Accessory(net, {anyone: true, mac: '12:34:56:78:9a:bc', name: 'Anyone'}, this)) + new Accessory(net, {anyone: true, mac: '12:34:56:78:9a:bc', name: 'Anyone'}, this) } @@ -141,12 +141,16 @@ module.exports = { const removeCachedDevices = function() { this.accessories.forEach(accessory => { + // if anyone sensor + if (accessory.context.serial === '12:34:56:78:9a:bc' && this.anyoneSensor) + return + const deviceInConfig = this.devicesConfig.find(device => device.mac.toLowerCase() === accessory.context.serial || device.ip === accessory.context.serial) if (deviceInConfig) return else { // unregistering accessory - this.log(`Unregistering disconnected device: "${accessory.displayName}" (${accessory.context.serial}`) + this.log(`Unregistering disconnected device: "${accessory.displayName}" (${accessory.context.serial})`) this.api.unregisterPlatformAccessories(this.PLUGIN_NAME, this.PLATFORM_NAME, [accessory]) }