Skip to content

Commit

Permalink
Workaround: bridge state isn't always updated
Browse files Browse the repository at this point in the history
See #132.
  • Loading branch information
ebaauw committed Apr 3, 2024
1 parent 814314b commit 2e27cca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/NbAccessory/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ class Bridge extends AccessoryDelegate {
this.warn('heartbeat error: %s', error)
}
}
// Workaround: bridge state isn't always updated
for (const id in this.smartLocks) {
try {
if (this.smartLocks[id].service.needRefresh) {
const response = await this.smartLocks[id].refresh()
const state = response.body
this.debug('device state refresh: %j', state)
this.smartLocks[id].update(state)
}
} catch (error) {
this.warn('heartbeat error: %s', error)
}
}
// End workaround
} catch (error) {
this.warn('heartbeat error: %s', error)
}
Expand Down
9 changes: 9 additions & 0 deletions lib/NbService/SmartLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ class SmartLock extends ServiceDelegate {

update (state) {
if (state.state != null) {
// Workaround: bridge state isn't always updated
this.needRefresh = this.previousState === state.state && [
NbClient.LockStates.UNLOCKED_LOCK_N_GO,
NbClient.LockStates.LOCKING,
NbClient.LockStates.UNLOCKING,
NbClient.LockStates.UNLATCHING
].includes(state.state)
this.previousState = state.state
// End workaround
switch (state.state) {
case NbClient.LockStates.UNLOCKED:
case NbClient.LockStates.UNLATCHED:
Expand Down

0 comments on commit 2e27cca

Please sign in to comment.