Skip to content

Commit

Permalink
feat: show inclusion state on UI
Browse files Browse the repository at this point in the history
Fixes #3516
  • Loading branch information
robertsLando committed Jan 17, 2024
1 parent 76802d5 commit c201821
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/lib/ZwaveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {
FirmwareUpdateInfo,
PartialZWaveOptions,
InclusionUserCallbacks,
InclusionState,
} from 'zwave-js'
import { getEnumMemberName, parseQRCodeString } from 'zwave-js/Utils'
import { logsDir, nvmBackupsDir, storeDir } from '../config/app'
Expand Down Expand Up @@ -700,6 +701,9 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
validateDSKAndEnterPIN: this._onValidateDSK.bind(this),
abort: this._onAbortInclusion.bind(this),
}
private _inclusionStateInterval: NodeJS.Timeout

private _inclusionState: InclusionState = undefined

public get driverReady() {
return this.driver && this._driverReady && !this.closed
Expand Down Expand Up @@ -1101,6 +1105,11 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {
this.closed = true
this.driverReady = false

if (this._inclusionStateInterval) {
clearInterval(this._inclusionStateInterval)
this._inclusionStateInterval = null
}

if (this.commandsTimeout) {
clearTimeout(this.commandsTimeout)
this.commandsTimeout = null
Expand Down Expand Up @@ -4206,6 +4215,36 @@ class ZwaveClient extends TypedEventEmitter<ZwaveClientEventCallbacks> {

this._updateControllerStatus('Driver ready')

this._inclusionStateInterval = setInterval(() => {
if (
this._driver.controller.inclusionState !== this._inclusionState
) {
this._inclusionState = this._driver.controller.inclusionState
let message = ''

switch (this._inclusionState) {
case InclusionState.Idle:
message = 'Controller is idle'
break
case InclusionState.Including:
message = 'Inclusion is active'
break
case InclusionState.Excluding:
message = 'Exclusion is active'
break
case InclusionState.Busy:
message =
'Waiting for inclusion/exclusion to complete...'
break
case InclusionState.SmartStart:
message = 'SmartStart inclusion is active'
break
}

this._updateControllerStatus(message)
}
}, 2000)

try {
// this must be done only after driver is ready
this._scheduledConfigCheck().catch(() => {
Expand Down

0 comments on commit c201821

Please sign in to comment.