From 19bfc54c8283545df1095579d8736091fd58eb7b Mon Sep 17 00:00:00 2001 From: Nicolas Camenisch Date: Thu, 22 Jul 2021 14:55:45 +0200 Subject: [PATCH 1/2] Fix PositionableAbility.targetPosition jumping to 0/100 --- abilities/base.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/abilities/base.js b/abilities/base.js index 1aa8a79..96da0fe 100644 --- a/abilities/base.js +++ b/abilities/base.js @@ -83,6 +83,7 @@ module.exports = homebridge => { this._setPositionTimeout = null this._targetPosition = null this._targetPositionTimeout = null + this._prevStopPosition = 0 } /** @@ -229,10 +230,6 @@ module.exports = homebridge => { newValue ) - this.service - .getCharacteristic(Characteristic.CurrentPosition) - .setValue(this.position) - this._updateTargetPositionDebounced() } @@ -261,11 +258,17 @@ module.exports = homebridge => { if (state === 'stop') { targetPosition = position - } else if (state === 'open' && this.targetPosition <= position) { + this._prevStopPosition = position + + this.service + .getCharacteristic(Characteristic.CurrentPosition) + .setValue(position) + + } else if (state === 'open' && this.targetPosition === this._prevStopPosition) { // we don't know what the target position is here, but we set it // to 100 so that the interface shows that the roller is opening targetPosition = 100 - } else if (state === 'close' && this.targetPosition >= position) { + } else if (state === 'close' && this.targetPosition === this._prevStopPosition) { // we don't know what the target position is here, but we set it // to 0 so that the interface shows that the roller is closing targetPosition = 0 From fd022d0aba750c32a2de34495937bae1d2fd251f Mon Sep 17 00:00:00 2001 From: Nicolas Camenisch Date: Thu, 22 Jul 2021 16:05:39 +0200 Subject: [PATCH 2/2] Fix HomeKit targetPosition getting out of sync --- abilities/base.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/abilities/base.js b/abilities/base.js index 96da0fe..a3ae70f 100644 --- a/abilities/base.js +++ b/abilities/base.js @@ -165,11 +165,15 @@ module.exports = homebridge => { callback() - if (this.targetPosition === newValue || - this._setPositionTimeout !== null) { + if (this.targetPosition === newValue) { return } + if (this._setPositionTimeout !== null) { + clearTimeout(this._setPositionTimeout) + this.__setPositionTimeout = null + } + this._setPositionTimeout = setTimeout(async () => { this.log.debug( 'Setting',