From fd2728c02ced0b7af9a9ceb6a496465ce7072740 Mon Sep 17 00:00:00 2001 From: Charles Garwood Date: Mon, 17 May 2021 11:15:01 -0400 Subject: [PATCH] Fix Z-Wave JS add node wizard and add interview status (#9145) --- .../zwave_js/dialog-zwave_js-add-node.ts | 126 +++++++++++++++++- src/translations/en.json | 6 +- 2 files changed, 124 insertions(+), 8 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts index 484b240212..0de86314ba 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-add-node.ts @@ -34,8 +34,14 @@ class DialogZWaveJSAddNode extends LitElement { @state() private _status = ""; + @state() private _nodeAdded = false; + @state() private _device?: ZWaveJSAddNodeDevice; + @state() private _stages?: string[]; + + private _stoppedTimeout?: any; + private _addNodeTimeoutHandle?: number; private _subscribed?: Promise<() => Promise>; @@ -128,6 +134,40 @@ class DialogZWaveJSAddNode extends LitElement { ` : ``} + ${this._status === "interviewing" + ? html` +
+ +
+

+ ${this.hass.localize( + "ui.panel.config.zwave_js.add_node.interview_started" + )} +

+ ${this._stages + ? html`
+ ${this._stages.map( + (stage) => html` + + + ${stage} + + ` + )} +
` + : ""} +
+
+ + ${this.hass.localize("ui.panel.config.zwave_js.common.close")} + + ` + : ``} ${this._status === "failed" ? html`
@@ -141,6 +181,21 @@ class DialogZWaveJSAddNode extends LitElement { "ui.panel.config.zwave_js.add_node.inclusion_failed" )}

+ ${this._stages + ? html`
+ ${this._stages.map( + (stage) => html` + + + ${stage} + + ` + )} +
` + : ""}
@@ -168,6 +223,21 @@ class DialogZWaveJSAddNode extends LitElement { )} + ${this._stages + ? html`
+ ${this._stages.map( + (stage) => html` + + + ${stage} + + ` + )} +
` + : ""} @@ -211,16 +281,41 @@ class DialogZWaveJSAddNode extends LitElement { this._status = "failed"; } if (message.event === "inclusion stopped") { - if (this._status !== "finished") { - this._status = ""; - } - this._unsubscribe(); + // we get the inclusion stopped event before the node added event + // during a successful inclusion. so we set a timer to wait 3 seconds + // to give the node added event time to come in before assuming it + // timed out or was cancelled and unsubscribing. + this._stoppedTimeout = setTimeout(() => { + if (!this._nodeAdded) { + this._status = ""; + this._unsubscribe(); + this._stoppedTimeout = undefined; + } + }, 3000); } if (message.event === "device registered") { this._device = message.device; + } + if (message.event === "node added") { + this._nodeAdded = true; + if (this._stoppedTimeout) { + clearTimeout(this._stoppedTimeout); + } + this._status = "interviewing"; + } + + if (message.event === "interview completed") { this._status = "finished"; this._unsubscribe(); } + + if (message.event === "interview stage completed") { + if (this._stages === undefined) { + this._stages = [message.stage]; + } else { + this._stages = [...this._stages, message.stage]; + } + } } private _unsubscribe(): void { @@ -246,7 +341,13 @@ class DialogZWaveJSAddNode extends LitElement { this._unsubscribe(); this.entry_id = undefined; this._status = ""; + this._nodeAdded = false; this._device = undefined; + this._stages = undefined; + if (this._stoppedTimeout) { + clearTimeout(this._stoppedTimeout); + this._stoppedTimeout = undefined; + } this._use_secure_inclusion = false; fireEvent(this, "dialog-closed", { dialog: this.localName }); @@ -261,11 +362,24 @@ class DialogZWaveJSAddNode extends LitElement { } .success { - color: green; + color: var(--success-color); } .failed { - color: red; + color: var(--warning-color); + } + + .stages { + margin-top: 16px; + } + + .flex-container .stage ha-svg-icon { + width: 16px; + height: 16px; + margin-right: 0px; + } + .stage { + padding: 8px; } blockquote { diff --git a/src/translations/en.json b/src/translations/en.json index 00a5030c59..670cff6250 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2633,8 +2633,10 @@ "controller_in_inclusion_mode": "Your Z-Wave controller is now in inclusion mode.", "follow_device_instructions": "Follow the directions that came with your device to trigger pairing on the device.", "inclusion_failed": "The node could not be added. Please check the logs for more information.", - "inclusion_finished": "The node has been added. It may take a few minutes for all entities to show up as we finish setting up the node in the background.", - "view_device": "View Device" + "inclusion_finished": "The node has been added.", + "view_device": "View Device", + "interview_started": "The device is being interviewed. This may take some time.", + "interview_failed": "The device interview failed. Additional information may be available in the logs." }, "remove_node": { "title": "Remove a Z-Wave Node",