Skip to content

Commit

Permalink
Fix for Garage Door handling
Browse files Browse the repository at this point in the history
  • Loading branch information
balansse committed Jun 29, 2022
1 parent 9614d3f commit cee3fb8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
34 changes: 24 additions & 10 deletions lib/accessories/garage_door.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ 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)
callback(new Error(`An error occurred while setting the garage door state: ${err}`))
}
}

getGarageDoorState() {
getGarageDoorCurrentState() {
switch(this.data.Status){
case VivintDict.GarageDoorStates.Unknown: // unknown state but this eliminates double notification
case VivintDict.GarageDoorStates.Closed:
Expand All @@ -42,20 +43,33 @@ 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:
return this.Characteristic.CurrentDoorState.STOPPED
}
}

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())
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/device_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cee3fb8

Please sign in to comment.