From 89063584b01ce6c6f1c3dd466ea49a73445cc63b Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Thu, 18 Jan 2024 14:57:15 +0100 Subject: [PATCH] feat: show inclusion state on UI (#3527) --- api/lib/ZwaveClient.ts | 27 ++++++++++++++++++++ src/App.vue | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/api/lib/ZwaveClient.ts b/api/lib/ZwaveClient.ts index 9580f4e86ab..30836c8f452 100644 --- a/api/lib/ZwaveClient.ts +++ b/api/lib/ZwaveClient.ts @@ -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' @@ -594,6 +595,7 @@ export type ZUIDriverInfo = { lastUpdate?: number status?: ZwaveClientStatus cntStatus?: string + inclusionState?: InclusionState appVersion?: string zwaveVersion?: string serverVersion?: string @@ -700,6 +702,9 @@ class ZwaveClient extends TypedEventEmitter { 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 @@ -1101,6 +1106,11 @@ class ZwaveClient extends TypedEventEmitter { this.closed = true this.driverReady = false + if (this._inclusionStateInterval) { + clearInterval(this._inclusionStateInterval) + this._inclusionStateInterval = null + } + if (this.commandsTimeout) { clearTimeout(this.commandsTimeout) this.commandsTimeout = null @@ -1175,6 +1185,7 @@ class ZwaveClient extends TypedEventEmitter { info: this.getInfo(), error: this.error, cntStatus: this.cntStatus, + inclusionState: this._inclusionState, } } @@ -2708,6 +2719,7 @@ class ZwaveClient extends TypedEventEmitter { info.status = this.status info.error = this.error info.cntStatus = this._cntStatus + info.inclusionState = this._inclusionState info.appVersion = utils.getVersion() info.zwaveVersion = libVersion info.serverVersion = serverVersion @@ -4206,6 +4218,20 @@ class ZwaveClient extends TypedEventEmitter { this._updateControllerStatus('Driver ready') + this._inclusionStateInterval = setInterval(() => { + if ( + this._driver.controller.inclusionState !== this._inclusionState + ) { + this._inclusionState = this._driver.controller.inclusionState + + this.sendToSocket(socketEvents.controller, { + status: this._cntStatus, + error: this._error, + inclusionState: this._inclusionState, + }) + } + }, 2000) + try { // this must be done only after driver is ready this._scheduledConfigCheck().catch(() => { @@ -4497,6 +4523,7 @@ class ZwaveClient extends TypedEventEmitter { this.sendToSocket(socketEvents.controller, { status, error: this._error, + inclusionState: this._inclusionState, }) } } diff --git a/src/App.vue b/src/App.vue index e3891e3c3b8..611b1a7b4a0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -104,6 +104,21 @@ + + + {{ inclusionState.message }} + +