diff --git a/lib/accessories/garage_door.js b/lib/accessories/garage_door.js index 3791a0e..b8afaca 100644 --- a/lib/accessories/garage_door.js +++ b/lib/accessories/garage_door.js @@ -8,21 +8,22 @@ class GarageDoor extends Device { this.service .getCharacteristic(this.Characteristic.CurrentDoorState) - .on('get', (callback) => callback(null, this.getGarageDoorState())); + .on('get', (callback) => callback(null, this.getGarageDoorCurrentState())); this.service .getCharacteristic(this.Characteristic.TargetDoorState) - //.on('get', (callback) => callback(null, this.doorCurrentValue())) + .on('get', (callback) => callback(null, this.getGarageDoorTargetState())) .on('set', async (state, callback) => this.setTargetState(state, callback)) - this.notify() + this.notify() } async setTargetState(targetState, callback) { - let locked = (targetState == this.Characteristic.LockTargetState.SECURED) + let targetVivintState = targetState == this.Characteristic.TargetDoorState.CLOSED ? + VivintDict.GarageDoorStates.Closing : VivintDict.GarageDoorStates.Opening try { callback() - await this.vivintApi.setGarageDoorState(this.id, locked) + await this.vivintApi.setGarageDoorState(this.id, targetVivintState) } catch (err) { this.log.error("Failure setting garage door state:", err) @@ -30,7 +31,7 @@ class GarageDoor extends Device { } } - getGarageDoorState() { + getGarageDoorCurrentState() { switch(this.data.Status){ case VivintDict.GarageDoorStates.Unknown: // unknown state but this eliminates double notification case VivintDict.GarageDoorStates.Closed: @@ -42,7 +43,7 @@ class GarageDoor extends Device { case VivintDict.GarageDoorStates.Opening: return this.Characteristic.CurrentDoorState.OPENING - case VivintDict.GarageDoorStates.Open: + case VivintDict.GarageDoorStates.Opened: return this.Characteristic.CurrentDoorState.OPEN default: @@ -50,12 +51,25 @@ class GarageDoor extends Device { } } + getGarageDoorTargetState() { + switch(this.data.Status){ + case VivintDict.GarageDoorStates.Opening: + case VivintDict.GarageDoorStates.Opened: + return this.Characteristic.TargetDoorState.OPEN + + case VivintDict.GarageDoorStates.Unknown: // unknown state but this eliminates double notification + case VivintDict.GarageDoorStates.Closed: + case VivintDict.GarageDoorStates.Closing: + default: + return this.Characteristic.TargetDoorState.CLOSED + } + } + notify() { super.notify() if (this.service) { - let state = this.getGarageDoorState() - this.service.updateCharacteristic(this.Characteristic.CurrentDoorState, state) - this.service.updateCharacteristic(this.Characteristic.TargetDoorState, state == this.Characteristic.TargetDoorState.CLOSED) + this.service.updateCharacteristic(this.Characteristic.CurrentDoorState, this.getGarageDoorCurrentState()) + this.service.updateCharacteristic(this.Characteristic.TargetDoorState, this.getGarageDoorTargetState()) } } diff --git a/lib/device_set.js b/lib/device_set.js index 54639fa..57975fa 100644 --- a/lib/device_set.js +++ b/lib/device_set.js @@ -63,9 +63,10 @@ function DeviceSetModule(config, log, homebridge, vivintApi) { } handleMessage(message) { - if (message.Data && message.Data.PlatformContext) { + if (message.Data) { - if (message.Data.PlatformContext.Timestamp < this.lastSnapshotTime) { + //Messages from Nest and MyQ devices does not have PlatformContext info + if (message.Data.PlatformContext && message.Data.PlatformContext.Timestamp < this.lastSnapshotTime) { log.warn("Ignoring stale update", message.Data.PlatformContext.Timestamp, "<", this.lastSnapshotTime) return; }