From 7c5496482f81e2fe54d8b193509038ea639f01bd Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 14 Oct 2023 03:00:11 -0400 Subject: [PATCH 01/14] Add Z-Wave controller hard reset device action --- src/data/zwave_js.ts | 9 ++ .../zwave_js/device-actions.ts | 19 ++- .../dialog-zwave_js-hard-reset-controller.ts | 122 ++++++++++++++++++ ...w-dialog-zwave_js-hard-reset-controller.ts | 19 +++ ...ow-dialog-zwave_js-update-firmware-node.ts | 2 +- src/translations/en.json | 8 ++ 6 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts create mode 100644 src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller.ts diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index 1c73185656b2..fd284785fff3 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -757,6 +757,15 @@ export const fetchZwaveNodeFirmwareUpdateCapabilities = ( device_id, }); +export const hardResetController = ( + hass: HomeAssistant, + entry_id: string +): Promise => + hass.callWS({ + type: "zwave_js/hard_reset_controller", + entry_id, + }); + export const uploadFirmwareAndBeginUpdate = async ( hass: HomeAssistant, device_id: string, diff --git a/src/panels/config/devices/device-detail/integration-elements/zwave_js/device-actions.ts b/src/panels/config/devices/device-detail/integration-elements/zwave_js/device-actions.ts index d6d4af86de27..5fcdb6585115 100644 --- a/src/panels/config/devices/device-detail/integration-elements/zwave_js/device-actions.ts +++ b/src/panels/config/devices/device-detail/integration-elements/zwave_js/device-actions.ts @@ -19,8 +19,9 @@ import { showZWaveJSRebuildNodeRoutesDialog } from "../../../../integrations/int import { showZWaveJSNodeStatisticsDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics"; import { showZWaveJSReinterviewNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node"; import { showZWaveJSRemoveFailedNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-failed-node"; -import { showZWaveJUpdateFirmwareNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node"; +import { showZWaveJSUpdateFirmwareNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node"; import type { DeviceAction } from "../../../ha-config-device-page"; +import { showZWaveJSHardResetControllerDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller"; export const getZwaveDeviceActions = async ( el: HTMLElement, @@ -136,7 +137,7 @@ export const getZwaveDeviceActions = async ( confirmText: hass.localize("ui.common.yes"), })) ) { - showZWaveJUpdateFirmwareNodeDialog(el, { + showZWaveJSUpdateFirmwareNodeDialog(el, { device, }); } @@ -144,5 +145,19 @@ export const getZwaveDeviceActions = async ( }); } + if (nodeStatus.is_controller_node) { + actions.push({ + label: hass.localize( + "ui.panel.config.zwave_js.device_info.hard_reset_controller" + ), + icon: mdiDeleteForever, + action: async () => { + showZWaveJSHardResetControllerDialog(el, { + entryId, + }); + }, + }); + } + return actions; }; diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts new file mode 100644 index 000000000000..41915abae3fc --- /dev/null +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -0,0 +1,122 @@ +import { mdiDeleteForever } from "@mdi/js"; +import "@material/mwc-button/mwc-button"; +import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; +import { customElement, property, state } from "lit/decorators"; +import { fireEvent } from "../../../../../common/dom/fire_event"; +import { createCloseHeading } from "../../../../../components/ha-dialog"; +import "../../../../../components/ha-svg-icon"; +import { hardResetController } from "../../../../../data/zwave_js"; +import { haStyleDialog } from "../../../../../resources/styles"; +import { HomeAssistant } from "../../../../../types"; +import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller"; +import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box"; + +@customElement("dialog-zwave_js-hard-reset-controller") +class DialogZWaveJSHardResetController extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @state() private entry_id?: string; + + @state() private _done = false; + + public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { + this.entry_id = params.entryId; + } + + public closeDialog(): void { + this.entry_id = undefined; + this._done = false; + + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } + + protected render() { + if (!this.entry_id) { + return nothing; + } + + return html` + ${!this._done + ? html`

+ ${this.hass.localize( + `ui.panel.config.zwave_js.hard_reset_controller.success` + )} +

` + : html`
+
+ +
+

+ ${this.hass.localize( + `ui.panel.config.zwave_js.hard_reset_controller.dialog_body` + )} +

+
+ + ${this.hass.localize("ui.common.continue")} + + + ${this.hass.localize("ui.common.cancel")} + `} +
`; + } + + private async _hardResetController(): Promise { + if ( + await showConfirmationDialog(this, { + text: this.hass.localize( + `ui.panel.config.zwave_js.hard_reset_controller.final_warning` + ), + dismissText: this.hass.localize("ui.common.cancel"), + confirmText: this.hass.localize("ui.common.continue"), + }) + ) { + await hardResetController(this.hass, this.entry_id!); + this._done = true; + } + } + + static get styles(): CSSResultGroup { + return [ + haStyleDialog, + css` + .icon { + color: var(--label-badge-red); + } + .flex-container { + display: flex; + align-items: center; + margin-bottom: 5px; + } + + ha-svg-icon { + width: 68px; + height: 48px; + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "dialog-zwave_js-hard-reset-controller": DialogZWaveJSHardResetController; + } +} diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller.ts new file mode 100644 index 000000000000..fa46ec804f44 --- /dev/null +++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-hard-reset-controller.ts @@ -0,0 +1,19 @@ +import { fireEvent } from "../../../../../common/dom/fire_event"; + +export interface ZWaveJSHardResetControllerDialogParams { + entryId: string; +} + +export const loadHardResetControllerDialog = () => + import("./dialog-zwave_js-hard-reset-controller"); + +export const showZWaveJSHardResetControllerDialog = ( + element: HTMLElement, + hardResetControllerDialogParams: ZWaveJSHardResetControllerDialogParams +): void => { + fireEvent(element, "show-dialog", { + dialogTag: "dialog-zwave_js-hard-reset-controller", + dialogImport: loadHardResetControllerDialog, + dialogParams: hardResetControllerDialogParams, + }); +}; diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node.ts index 69c7cc47290c..ee3efb760eb4 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-update-firmware-node.ts @@ -8,7 +8,7 @@ export interface ZWaveJSUpdateFirmwareNodeDialogParams { export const loadUpdateFirmwareNodeDialog = () => import("./dialog-zwave_js-update-firmware-node"); -export const showZWaveJUpdateFirmwareNodeDialog = ( +export const showZWaveJSUpdateFirmwareNodeDialog = ( element: HTMLElement, updateFirmwareNodeDialogParams: ZWaveJSUpdateFirmwareNodeDialogParams ): void => { diff --git a/src/translations/en.json b/src/translations/en.json index 3c9bfce68445..87361751bd14 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3998,11 +3998,19 @@ "remove_failed": "Remove failed", "update_firmware": "Update", "highest_security": "Highest security", + "hard_reset_controller": "Factory reset", "unknown": "Unknown", "zwave_plus": "Z-Wave Plus", "zwave_plus_version": "Version {version}", "node_statistics": "Statistics" }, + "hard_reset_controller": { + "success": "Your controller has been reset to factory settings, you can now close this dialog!", + "dialog_body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", + "title_not_done": "Reset Controller to Factory Settings", + "title_done": "Controller Reset Complete", + "final_warning": "This action cannot be undone unless you have an NVM backup from your controller." + }, "node_statistics": { "title": "Device statistics", "commands_tx": { From 1a6ac6d295944fb5c48dcb0258005824754459e4 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 14 Oct 2023 09:52:07 -0400 Subject: [PATCH 02/14] bug fix --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 41915abae3fc..44a6edd008f3 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -35,7 +35,7 @@ class DialogZWaveJSHardResetController extends LitElement { return nothing; } - return html` - ${!this._done + ${this._done ? html`

${this.hass.localize( `ui.panel.config.zwave_js.hard_reset_controller.success` From 274706c507f0d6907b70ecb373e6a4febeb3b0b3 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 14 Oct 2023 11:00:11 -0400 Subject: [PATCH 03/14] Add non working history.back --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 44a6edd008f3..ecae243ec8b5 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -25,9 +25,12 @@ class DialogZWaveJSHardResetController extends LitElement { public closeDialog(): void { this.entry_id = undefined; - this._done = false; fireEvent(this, "dialog-closed", { dialog: this.localName }); + if (this._done) { + this._done = false; + setTimeout(() => history.back(), 0); + } } protected render() { From a55021e51c4fab8ce419aa4f68905047c61d3424 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sat, 14 Oct 2023 11:07:33 -0400 Subject: [PATCH 04/14] don't think timeout is needed here --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index ecae243ec8b5..4a95e2e69d6c 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -29,7 +29,7 @@ class DialogZWaveJSHardResetController extends LitElement { fireEvent(this, "dialog-closed", { dialog: this.localName }); if (this._done) { this._done = false; - setTimeout(() => history.back(), 0); + history.back(); } } From d4e48bb7bc5bdb7c90d739026322c08377afaa41 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Sun, 15 Oct 2023 11:32:30 -0400 Subject: [PATCH 05/14] Clarify that this is network specific --- src/translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/translations/en.json b/src/translations/en.json index 87361751bd14..10ae4d32a28f 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4006,7 +4006,7 @@ }, "hard_reset_controller": { "success": "Your controller has been reset to factory settings, you can now close this dialog!", - "dialog_body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", + "dialog_body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", "title_not_done": "Reset Controller to Factory Settings", "title_done": "Controller Reset Complete", "final_warning": "This action cannot be undone unless you have an NVM backup from your controller." From 174126a1e9053585269b702401a538cda9d2c1cb Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Oct 2023 07:29:45 -0400 Subject: [PATCH 06/14] Update dialog-zwave_js-hard-reset-controller.ts Co-authored-by: Bram Kragten --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 4a95e2e69d6c..d4d1d74381ad 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -15,7 +15,7 @@ import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dial class DialogZWaveJSHardResetController extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @state() private entry_id?: string; + @state() private _entryId?: string; @state() private _done = false; From aee12c9f4544363108cc3f8f48aeb3f2c261cafc Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Oct 2023 08:15:20 -0400 Subject: [PATCH 07/14] review --- .../dialog-zwave_js-hard-reset-controller.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index d4d1d74381ad..909de98ecdf6 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -10,6 +10,7 @@ import { haStyleDialog } from "../../../../../resources/styles"; import { HomeAssistant } from "../../../../../types"; import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller"; import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box"; +import { navigate } from "../../../../../common/navigate"; @customElement("dialog-zwave_js-hard-reset-controller") class DialogZWaveJSHardResetController extends LitElement { @@ -20,21 +21,18 @@ class DialogZWaveJSHardResetController extends LitElement { @state() private _done = false; public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { - this.entry_id = params.entryId; + this._entryId = params.entryId; } public closeDialog(): void { - this.entry_id = undefined; + this._entryId = undefined; + this._done = false; fireEvent(this, "dialog-closed", { dialog: this.localName }); - if (this._done) { - this._done = false; - history.back(); - } } protected render() { - if (!this.entry_id) { + if (!this._entryId) { return nothing; } @@ -91,8 +89,9 @@ class DialogZWaveJSHardResetController extends LitElement { confirmText: this.hass.localize("ui.common.continue"), }) ) { - await hardResetController(this.hass, this.entry_id!); + await hardResetController(this.hass, this._entryId!); this._done = true; + navigate(`/config/devices/dashboard?config_entry=${this._entryId}`); } } From 731d93614889d8fbd85a0d9c178d64207af2f321 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 18 Oct 2023 02:21:17 -0400 Subject: [PATCH 08/14] navigate to new device entry --- .../dialog-zwave_js-hard-reset-controller.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 909de98ecdf6..fece627a39b8 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -2,6 +2,7 @@ import { mdiDeleteForever } from "@mdi/js"; import "@material/mwc-button/mwc-button"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; +import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { createCloseHeading } from "../../../../../components/ha-dialog"; import "../../../../../components/ha-svg-icon"; @@ -11,6 +12,7 @@ import { HomeAssistant } from "../../../../../types"; import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller"; import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box"; import { navigate } from "../../../../../common/navigate"; +import { fetchDeviceRegistry } from "../../../../../data/device_registry"; @customElement("dialog-zwave_js-hard-reset-controller") class DialogZWaveJSHardResetController extends LitElement { @@ -20,6 +22,10 @@ class DialogZWaveJSHardResetController extends LitElement { @state() private _done = false; + private _devices?: DeviceRegistryEntry[]; + + private _subscribedDeviceRegistryUpdates?: Promise; + public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { this._entryId = params.entryId; } @@ -28,6 +34,8 @@ class DialogZWaveJSHardResetController extends LitElement { this._entryId = undefined; this._done = false; + this._unsubscribe(); + fireEvent(this, "dialog-closed", { dialog: this.localName }); } @@ -89,9 +97,29 @@ class DialogZWaveJSHardResetController extends LitElement { confirmText: this.hass.localize("ui.common.continue"), }) ) { + this._subscribedDeviceRegistryUpdates = + this.hass.connection.subscribeEvents( + () => + fetchDeviceRegistry(this.hass.connection).then((devices) => { + const deviceEntries = devices.filter((device) => + device.config_entries.includes(this._entryId!) + ); + if (deviceEntries.length === 1) { + navigate(`/config/devices/device/${deviceEntries[0].id}`); + this._unsubscribe(); + } + }), + "device_registry_updated" + ); await hardResetController(this.hass, this._entryId!); this._done = true; - navigate(`/config/devices/dashboard?config_entry=${this._entryId}`); + } + } + + private _unsubscribe() { + if (this._subscribedDeviceRegistryUpdates) { + this._subscribedDeviceRegistryUpdates.then((unsub) => unsub()); + this._subscribedDeviceRegistryUpdates = undefined; } } From 341cf101c23187f74540d901d8e19befca90150d Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 18 Oct 2023 02:27:18 -0400 Subject: [PATCH 09/14] changes --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 8 +++++--- src/translations/en.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index fece627a39b8..62821215f467 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -22,8 +22,6 @@ class DialogZWaveJSHardResetController extends LitElement { @state() private _done = false; - private _devices?: DeviceRegistryEntry[]; - private _subscribedDeviceRegistryUpdates?: Promise; public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { @@ -105,7 +103,11 @@ class DialogZWaveJSHardResetController extends LitElement { device.config_entries.includes(this._entryId!) ); if (deviceEntries.length === 1) { - navigate(`/config/devices/device/${deviceEntries[0].id}`); + setTimeout( + () => + navigate(`/config/devices/device/${deviceEntries[0].id}`), + 0 + ); this._unsubscribe(); } }), diff --git a/src/translations/en.json b/src/translations/en.json index 10ae4d32a28f..404162cfa0ba 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4005,7 +4005,7 @@ "node_statistics": "Statistics" }, "hard_reset_controller": { - "success": "Your controller has been reset to factory settings, you can now close this dialog!", + "success": "Your controller has been reset to factory settings and is now restarting. Once it is back online, you will be redirected to the new device page as long as you keep this dialog open.", "dialog_body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", "title_not_done": "Reset Controller to Factory Settings", "title_done": "Controller Reset Complete", From ad4f651055000b9647f1d848997126ad3a869130 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:17:23 -0400 Subject: [PATCH 10/14] Simplify --- src/data/zwave_js.ts | 2 +- .../dialog-zwave_js-hard-reset-controller.ts | 100 ++++++++---------- src/translations/en.json | 5 +- 3 files changed, 46 insertions(+), 61 deletions(-) diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index fd284785fff3..fd5ee1b4c20e 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -760,7 +760,7 @@ export const fetchZwaveNodeFirmwareUpdateCapabilities = ( export const hardResetController = ( hass: HomeAssistant, entry_id: string -): Promise => +): Promise => hass.callWS({ type: "zwave_js/hard_reset_controller", entry_id, diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 62821215f467..4b6db2d2a821 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -1,8 +1,7 @@ -import { mdiDeleteForever } from "@mdi/js"; +import { mdiCheckCircle, mdiDeleteForever, mdiRestore } from "@mdi/js"; import "@material/mwc-button/mwc-button"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit"; import { customElement, property, state } from "lit/decorators"; -import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { createCloseHeading } from "../../../../../components/ha-dialog"; import "../../../../../components/ha-svg-icon"; @@ -12,7 +11,18 @@ import { HomeAssistant } from "../../../../../types"; import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller"; import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box"; import { navigate } from "../../../../../common/navigate"; -import { fetchDeviceRegistry } from "../../../../../data/device_registry"; + +enum ResetStatus { + NotStarted, + InProgress, + Done, +} + +const iconMap = { + [ResetStatus.NotStarted]: mdiDeleteForever, + [ResetStatus.InProgress]: mdiRestore, + [ResetStatus.Done]: mdiCheckCircle, +}; @customElement("dialog-zwave_js-hard-reset-controller") class DialogZWaveJSHardResetController extends LitElement { @@ -20,9 +30,7 @@ class DialogZWaveJSHardResetController extends LitElement { @state() private _entryId?: string; - @state() private _done = false; - - private _subscribedDeviceRegistryUpdates?: Promise; + @state() private _resetStatus = ResetStatus.NotStarted; public showDialog(params: ZWaveJSHardResetControllerDialogParams): void { this._entryId = params.entryId; @@ -30,9 +38,7 @@ class DialogZWaveJSHardResetController extends LitElement { public closeDialog(): void { this._entryId = undefined; - this._done = false; - - this._unsubscribe(); + this._resetStatus = ResetStatus.NotStarted; fireEvent(this, "dialog-closed", { dialog: this.localName }); } @@ -49,31 +55,30 @@ class DialogZWaveJSHardResetController extends LitElement { this.hass, this.hass.localize( `ui.panel.config.zwave_js.hard_reset_controller.title_${ - this._done ? "done" : "not_done" + this._resetStatus === ResetStatus.Done ? "done" : "not_done" }` ) )} > - ${this._done - ? html`

- ${this.hass.localize( - `ui.panel.config.zwave_js.hard_reset_controller.success` - )} -

` - : html`
-
- -
-

- ${this.hass.localize( - `ui.panel.config.zwave_js.hard_reset_controller.dialog_body` - )} -

-
- +
+ +
+ +

+ ${this.hass.localize( + `ui.panel.config.zwave_js.hard_reset_controller.${ + ResetStatus[this._resetStatus] + }` + )} +

+ + ${ + this._resetStatus === ResetStatus.NotStarted + ? html` @@ -81,7 +86,9 @@ class DialogZWaveJSHardResetController extends LitElement { ${this.hass.localize("ui.common.cancel")} - `} +
` + : nothing + }
`; } @@ -95,33 +102,10 @@ class DialogZWaveJSHardResetController extends LitElement { confirmText: this.hass.localize("ui.common.continue"), }) ) { - this._subscribedDeviceRegistryUpdates = - this.hass.connection.subscribeEvents( - () => - fetchDeviceRegistry(this.hass.connection).then((devices) => { - const deviceEntries = devices.filter((device) => - device.config_entries.includes(this._entryId!) - ); - if (deviceEntries.length === 1) { - setTimeout( - () => - navigate(`/config/devices/device/${deviceEntries[0].id}`), - 0 - ); - this._unsubscribe(); - } - }), - "device_registry_updated" - ); - await hardResetController(this.hass, this._entryId!); - this._done = true; - } - } - - private _unsubscribe() { - if (this._subscribedDeviceRegistryUpdates) { - this._subscribedDeviceRegistryUpdates.then((unsub) => unsub()); - this._subscribedDeviceRegistryUpdates = undefined; + this._resetStatus = ResetStatus.InProgress; + const deviceId = await hardResetController(this.hass, this._entryId!); + setTimeout(() => navigate(`/config/devices/device/${deviceId}`), 0); + this._resetStatus = ResetStatus.Done; } } diff --git a/src/translations/en.json b/src/translations/en.json index 404162cfa0ba..798feb49aab8 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4005,8 +4005,9 @@ "node_statistics": "Statistics" }, "hard_reset_controller": { - "success": "Your controller has been reset to factory settings and is now restarting. Once it is back online, you will be redirected to the new device page as long as you keep this dialog open.", - "dialog_body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", + "Done": "Your controller has been reset to factory settings and has been restarted! You can now close this dialog.", + "InProgress": "Your controller is being reset and restarted. Wait until the process is complete before closing this dialog", + "NotStarted": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", "title_not_done": "Reset Controller to Factory Settings", "title_done": "Controller Reset Complete", "final_warning": "This action cannot be undone unless you have an NVM backup from your controller." From beae59ebbc5f1e84274c72d7e1f051be386766d4 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:23:06 -0400 Subject: [PATCH 11/14] fix html --- .../dialog-zwave_js-hard-reset-controller.ts | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 4b6db2d2a821..6fac10ec4186 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -67,17 +67,15 @@ class DialogZWaveJSHardResetController extends LitElement { .class="icon" > +

+ ${this.hass.localize( + `ui.panel.config.zwave_js.hard_reset_controller.${ + ResetStatus[this._resetStatus] + }` + )} +

-

- ${this.hass.localize( - `ui.panel.config.zwave_js.hard_reset_controller.${ - ResetStatus[this._resetStatus] - }` - )} -

- - ${ - this._resetStatus === ResetStatus.NotStarted + ${this._resetStatus === ResetStatus.NotStarted ? html` ${this.hass.localize("ui.common.cancel")} ` - : nothing - } + : nothing} `; } From c4d052b25de5a71e002e1bbdf9f2bfc252ae174c Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:38:36 -0400 Subject: [PATCH 12/14] clean up keys --- .../dialog-zwave_js-hard-reset-controller.ts | 10 +++++----- src/translations/en.json | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 6fac10ec4186..ea132ad76d3f 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -54,9 +54,9 @@ class DialogZWaveJSHardResetController extends LitElement { .heading=${createCloseHeading( this.hass, this.hass.localize( - `ui.panel.config.zwave_js.hard_reset_controller.title_${ - this._resetStatus === ResetStatus.Done ? "done" : "not_done" - }` + `ui.panel.config.zwave_js.hard_reset_controller.${ + ResetStatus[this._resetStatus] + }.title` ) )} > @@ -71,7 +71,7 @@ class DialogZWaveJSHardResetController extends LitElement { ${this.hass.localize( `ui.panel.config.zwave_js.hard_reset_controller.${ ResetStatus[this._resetStatus] - }` + }.body` )}

@@ -93,7 +93,7 @@ class DialogZWaveJSHardResetController extends LitElement { if ( await showConfirmationDialog(this, { text: this.hass.localize( - `ui.panel.config.zwave_js.hard_reset_controller.final_warning` + `ui.panel.config.zwave_js.hard_reset_controller.confirmation` ), dismissText: this.hass.localize("ui.common.cancel"), confirmText: this.hass.localize("ui.common.continue"), diff --git a/src/translations/en.json b/src/translations/en.json index 798feb49aab8..9eadf11834e1 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4005,12 +4005,19 @@ "node_statistics": "Statistics" }, "hard_reset_controller": { - "Done": "Your controller has been reset to factory settings and has been restarted! You can now close this dialog.", - "InProgress": "Your controller is being reset and restarted. Wait until the process is complete before closing this dialog", - "NotStarted": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?", - "title_not_done": "Reset Controller to Factory Settings", - "title_done": "Controller Reset Complete", - "final_warning": "This action cannot be undone unless you have an NVM backup from your controller." + "NotStarted": { + "title": "Reset Controller to Factory Settings", + "body": "If you decide to move forward, you will reset your controller to factory settings. As a result, the controller will forget all devices it is paired with and all Z-Wave devices for this network will be removed from Home Assistant. If there are any devices still paired with the controller when it is reset, they will have to go through the exclusion process before they can be re-paired. Would you like to continue?" + }, + "InProgress": { + "title": "Resetting Controller", + "body": "Your controller is being reset and restarted. Wait until the process is complete before closing this dialog" + }, + "Done": { + "title": "Controller Reset Complete", + "body": "Your controller has been reset to factory settings and has been restarted! You can now close this dialog." + }, + "confirmation": "This action cannot be undone unless you have an NVM backup from your controller." }, "node_statistics": { "title": "Device statistics", From ee97f21333298f9fa13486ee3c9cdda5028cadf5 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 23 Oct 2023 15:55:31 +0200 Subject: [PATCH 13/14] Update src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index ea132ad76d3f..97f611252504 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -97,6 +97,7 @@ class DialogZWaveJSHardResetController extends LitElement { ), dismissText: this.hass.localize("ui.common.cancel"), confirmText: this.hass.localize("ui.common.continue"), + destructive: true }) ) { this._resetStatus = ResetStatus.InProgress; From edd748686934784c06b4704032b50e0b2f59a481 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 23 Oct 2023 17:57:33 +0200 Subject: [PATCH 14/14] Update dialog-zwave_js-hard-reset-controller.ts --- .../zwave_js/dialog-zwave_js-hard-reset-controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts index 97f611252504..b9dee78f21f9 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-hard-reset-controller.ts @@ -97,7 +97,7 @@ class DialogZWaveJSHardResetController extends LitElement { ), dismissText: this.hass.localize("ui.common.cancel"), confirmText: this.hass.localize("ui.common.continue"), - destructive: true + destructive: true, }) ) { this._resetStatus = ResetStatus.InProgress;