From c2fb1129cf281be5bf3ec470554e5beff8ab5bda Mon Sep 17 00:00:00 2001 From: Seyd <34152761+SeydX@users.noreply.github.com> Date: Thu, 26 Nov 2020 18:21:00 +0100 Subject: [PATCH] Fix MotionSensor --- src/accessories/outlet.js | 81 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/accessories/outlet.js b/src/accessories/outlet.js index 83d4a0c..f2ed9f4 100644 --- a/src/accessories/outlet.js +++ b/src/accessories/outlet.js @@ -193,52 +193,51 @@ class OutletAccessory { .getService(this.api.hap.Service.Outlet) .getCharacteristic(this.api.hap.Characteristic.Amperes) .updateValue(message.ENERGY.Current); - - if(this.Telegram){ - if(message.ENERGY.Power >= this.accessory.context.config.startValue && !this.accessory.context.started){ - - this.accessory.context.started = true; - + if(message.ENERGY.Power >= this.accessory.context.config.startValue && !this.accessory.context.started){ + + this.accessory.context.started = true; + + if(this.Telegram) this.Telegram.send('started', this.accessory.displayName); + + const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion'); + + if(motionAccessory) { + + motionAccessory + .getService(this.api.hap.Service.MotionSensor) + .getCharacteristic(this.api.hap.Characteristic.MotionDetected) + .updateValue(1); + + } else { + + Logger.info('Started', this.accessory.displayName); - const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion'); - - if(motionAccessory) { - - motionAccessory - .getService(this.api.hap.Service.MotionSensor) - .getCharacteristic(this.api.hap.Characteristic.MotionDetected) - .updateValue(1); - - } else { - - Logger.info('Started', this.accessory.displayName); - - } - - } else if(message.ENERGY.Power < this.accessory.context.config.startValue && this.accessory.context.started){ - - this.accessory.context.started = false; - + } + + } else if(message.ENERGY.Power < this.accessory.context.config.startValue && this.accessory.context.started){ + + this.accessory.context.started = false; + + if(this.Telegram) this.Telegram.send('finished', this.accessory.displayName); - - const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion'); - - if(motionAccessory) { - - motionAccessory - .getService(this.api.hap.Service.MotionSensor) - .getCharacteristic(this.api.hap.Characteristic.MotionDetected) - .updateValue(0); - - } else { - - Logger.info('Finished', this.accessory.displayName); - - } - + + const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion'); + + if(motionAccessory) { + + motionAccessory + .getService(this.api.hap.Service.MotionSensor) + .getCharacteristic(this.api.hap.Characteristic.MotionDetected) + .updateValue(0); + + } else { + + Logger.info('Finished', this.accessory.displayName); + } + } break;