From e9693435ceae7bac4be0466a2f501f337c752bf1 Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Fri, 3 Jan 2020 19:57:47 -0500 Subject: [PATCH] Added missing logic --- src/Accessories/DeviceButton.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Accessories/DeviceButton.ts b/src/Accessories/DeviceButton.ts index 9ed0016..4b66967 100644 --- a/src/Accessories/DeviceButton.ts +++ b/src/Accessories/DeviceButton.ts @@ -86,8 +86,8 @@ export class DeviceButton implements IAccessory { * Handler for switch set event * @param callback The callback function to call when complete */ - private onSwitchSet = async (activeState: boolean, callback: (error?: Error | null | undefined) => void) => { - if (!this._buttonInfo.IsStateful && activeState === this._buttonState) { + private onSwitchSet = async (newState: boolean, callback: (error?: Error | null | undefined) => void) => { + if (!this._buttonInfo.IsStateful && newState === this._buttonState) { return callback(); } @@ -101,12 +101,12 @@ export class DeviceButton implements IAccessory { //Execute command if (this._deviceCommand) { - await this._dataProvider.sendCommand(this._deviceCommand); - //change state if stateful - if (this._buttonInfo.IsStateful && this._buttonState != activeState) { - this._buttonState = activeState - } else { + if (this._buttonInfo.IsStateful && this._buttonState != newState) { + this._buttonState = newState + await this._dataProvider.sendCommand(this._deviceCommand); + } else if (!this._buttonInfo.IsStateful) { + await this._dataProvider.sendCommand(this._deviceCommand); this._switchService.getCharacteristic(Characteristic.On).updateValue(false); return callback(new Error("Normal Response")); }