-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add UI for Z-Wave JS Device Reinterview #8957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0fe4614
initial reinterview node UI commit
cgarwood 9099361
finish up
cgarwood 9641c80
css cleanup
cgarwood 8e917cc
small cleanups from code review
cgarwood 67188bb
unsubscribe cleanup
cgarwood 0e04a32
move subscribe to data/zwave_js.ts
cgarwood a5e6657
typing tweaks
cgarwood d93dc65
add note about closing dialog
cgarwood 293ceb6
Improve showing status of interview
cgarwood dc5b9dc
review comments
cgarwood 3dd6165
cleanup old stage code
cgarwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 262 additions & 0 deletions
262
...anels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-reinterview-node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| import "@material/mwc-button/mwc-button"; | ||
| import { mdiCheckCircle, mdiCloseCircle } from "@mdi/js"; | ||
| import { | ||
| CSSResult, | ||
| customElement, | ||
| html, | ||
| LitElement, | ||
| property, | ||
| internalProperty, | ||
| TemplateResult, | ||
| css, | ||
| } from "lit-element"; | ||
| import "../../../../../components/ha-circular-progress"; | ||
| import { createCloseHeading } from "../../../../../components/ha-dialog"; | ||
| import { haStyleDialog } from "../../../../../resources/styles"; | ||
| import { HomeAssistant } from "../../../../../types"; | ||
| import { ZWaveJSReinterviewNodeDialogParams } from "./show-dialog-zwave_js-reinterview-node"; | ||
| import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
| import { UnsubscribeFunc } from "home-assistant-js-websocket"; | ||
| import { reinterviewNode } from "../../../../../data/zwave_js"; | ||
|
|
||
| @customElement("dialog-zwave_js-reinterview-node") | ||
| class DialogZWaveJSReinterviewNode extends LitElement { | ||
| @property({ attribute: false }) public hass!: HomeAssistant; | ||
|
|
||
| @internalProperty() private entry_id?: string; | ||
|
|
||
| @internalProperty() private node_id?: number; | ||
|
|
||
| @internalProperty() private _status?: string; | ||
|
|
||
| @internalProperty() private _stages?: string[]; | ||
|
|
||
| private _subscribed?: Promise<UnsubscribeFunc>; | ||
|
|
||
| public async showDialog( | ||
| params: ZWaveJSReinterviewNodeDialogParams | ||
| ): Promise<void> { | ||
| this._stages = undefined; | ||
| this.entry_id = params.entry_id; | ||
| this.node_id = params.node_id; | ||
| } | ||
|
|
||
| protected render(): TemplateResult { | ||
| if (!this.entry_id) { | ||
| return html``; | ||
| } | ||
|
|
||
| return html` | ||
| <ha-dialog | ||
| open | ||
| @closed=${this.closeDialog} | ||
| .heading=${createCloseHeading( | ||
| this.hass, | ||
| this.hass.localize("ui.panel.config.zwave_js.reinterview_node.title") | ||
| )} | ||
| > | ||
| ${!this._status | ||
| ? html` | ||
| <p> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.introduction" | ||
| )} | ||
| </p> | ||
| <p> | ||
| <em> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.battery_device_warning" | ||
| )} | ||
| </em> | ||
| </p> | ||
| <mwc-button slot="primaryAction" @click=${this._startReinterview}> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.start_reinterview" | ||
| )} | ||
| </mwc-button> | ||
| ` | ||
| : ``} | ||
| ${this._status === "started" | ||
| ? html` | ||
| <div class="flex-container"> | ||
| <ha-circular-progress active></ha-circular-progress> | ||
| <div class="status"> | ||
| <p> | ||
| <b> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.in_progress" | ||
| )} | ||
| </b> | ||
| </p> | ||
| <p> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.run_in_background" | ||
| )} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <mwc-button slot="primaryAction" @click=${this.closeDialog}> | ||
| ${this.hass.localize("ui.panel.config.zwave_js.common.close")} | ||
| </mwc-button> | ||
| ` | ||
| : ``} | ||
| ${this._status === "failed" | ||
| ? html` | ||
| <div class="flex-container"> | ||
| <ha-svg-icon | ||
| .path=${mdiCloseCircle} | ||
| class="failed" | ||
| ></ha-svg-icon> | ||
| <div class="status"> | ||
| <p> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.interview_failed" | ||
| )} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <mwc-button slot="primaryAction" @click=${this.closeDialog}> | ||
| ${this.hass.localize("ui.panel.config.zwave_js.common.close")} | ||
| </mwc-button> | ||
| ` | ||
| : ``} | ||
| ${this._status === "finished" | ||
| ? html` | ||
| <div class="flex-container"> | ||
| <ha-svg-icon | ||
| .path=${mdiCheckCircle} | ||
| class="success" | ||
| ></ha-svg-icon> | ||
| <div class="status"> | ||
| <p> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.zwave_js.reinterview_node.interview_complete" | ||
| )} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| <mwc-button slot="primaryAction" @click=${this.closeDialog}> | ||
| ${this.hass.localize("ui.panel.config.zwave_js.common.close")} | ||
| </mwc-button> | ||
| ` | ||
| : ``} | ||
| ${this._stages | ||
| ? html` | ||
| <div class="stages"> | ||
| ${this._stages.map( | ||
| (stage) => html` | ||
| <span class="stage"> | ||
| <ha-svg-icon | ||
| .path=${mdiCheckCircle} | ||
| class="success" | ||
| ></ha-svg-icon> | ||
| ${stage} | ||
| </span> | ||
| ` | ||
| )} | ||
| </div> | ||
| ` | ||
| : ""} | ||
| </ha-dialog> | ||
| `; | ||
| } | ||
|
|
||
| private _startReinterview(): void { | ||
| if (!this.hass) { | ||
| return; | ||
| } | ||
| this._subscribed = reinterviewNode( | ||
| this.hass, | ||
| this.entry_id!, | ||
| this.node_id!, | ||
| this._handleMessage.bind(this) | ||
| ); | ||
| } | ||
|
|
||
| private _handleMessage(message: any): void { | ||
| if (message.event === "interview started") { | ||
| this._status = "started"; | ||
| } | ||
| if (message.event === "interview stage completed") { | ||
| if (this._stages === undefined) { | ||
| this._stages = [message.stage]; | ||
| } else { | ||
| this._stages = [...this._stages, message.stage]; | ||
| } | ||
| } | ||
| if (message.event === "interview failed") { | ||
| this._unsubscribe(); | ||
| this._status = "failed"; | ||
| } | ||
| if (message.event === "interview completed") { | ||
| this._unsubscribe(); | ||
| this._status = "finished"; | ||
| } | ||
| } | ||
|
|
||
| private _unsubscribe(): void { | ||
| if (this._subscribed) { | ||
| this._subscribed.then((unsub) => unsub()); | ||
| this._subscribed = undefined; | ||
| } | ||
| } | ||
|
|
||
| public closeDialog(): void { | ||
| this.entry_id = undefined; | ||
| this.node_id = undefined; | ||
| this._status = undefined; | ||
| this._stages = undefined; | ||
|
|
||
| this._unsubscribe(); | ||
|
|
||
| fireEvent(this, "dialog-closed", { dialog: this.localName }); | ||
| } | ||
|
|
||
| static get styles(): CSSResult[] { | ||
| return [ | ||
| haStyleDialog, | ||
| css` | ||
| .success { | ||
| color: var(--success-color); | ||
| } | ||
|
|
||
| .failed { | ||
| color: var(--warning-color); | ||
| } | ||
|
|
||
| .flex-container { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .stages { | ||
| margin-top: 16px; | ||
| } | ||
|
|
||
| .stage ha-svg-icon { | ||
| width: 16px; | ||
| height: 16px; | ||
| } | ||
| .stage { | ||
| padding: 8px; | ||
| } | ||
|
|
||
| ha-svg-icon { | ||
| width: 68px; | ||
| height: 48px; | ||
| } | ||
|
|
||
| .flex-container ha-circular-progress, | ||
| .flex-container ha-svg-icon { | ||
| margin-right: 20px; | ||
| } | ||
| `, | ||
| ]; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "dialog-zwave_js-reinterview-node": DialogZWaveJSReinterviewNode; | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
.../config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
|
|
||
| export interface ZWaveJSReinterviewNodeDialogParams { | ||
| entry_id: string; | ||
| node_id: number; | ||
| } | ||
|
|
||
| export const loadReinterviewNodeDialog = () => | ||
| import("./dialog-zwave_js-reinterview-node"); | ||
|
|
||
| export const showZWaveJSReinterviewNodeDialog = ( | ||
| element: HTMLElement, | ||
| reinterviewNodeDialogParams: ZWaveJSReinterviewNodeDialogParams | ||
| ): void => { | ||
| fireEvent(element, "show-dialog", { | ||
| dialogTag: "dialog-zwave_js-reinterview-node", | ||
| dialogImport: loadReinterviewNodeDialog, | ||
| dialogParams: reinterviewNodeDialogParams, | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.