From 9bdf180c7841fb5f8344b286c3ce662271322470 Mon Sep 17 00:00:00 2001
From: Petar Petrov
Date: Thu, 24 Oct 2024 16:24:03 +0300
Subject: [PATCH 1/2] ZwaveJS: Resume adding a device if the page is refreshed
---
.../zwave_js/dialog-zwave_js-add-node.ts | 6 ++-
.../zwave_js/dialog-zwave_js-remove-node.ts | 33 +++++++++---
.../show-dialog-zwave_js-remove-node.ts | 2 +
.../zwave_js/zwave_js-config-dashboard.ts | 52 +++++--------------
4 files changed, 48 insertions(+), 45 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 8955ff5c162c..48577c6d36e0 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
@@ -846,7 +846,11 @@ class DialogZWaveJSAddNode extends LitElement {
undefined,
undefined,
dsk
- );
+ ).catch((err) => {
+ this._error = err.message;
+ this._status = "failed";
+ return () => {};
+ });
this._addNodeTimeoutHandle = window.setTimeout(() => {
this._unsubscribe();
this._status = "timed_out";
diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
index 20c885405777..0e9f62f5ac2d 100644
--- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
+++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
@@ -2,6 +2,7 @@ import "@material/mwc-button/mwc-button";
import { mdiCheckCircle, mdiCloseCircle } from "@mdi/js";
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 "../../../../../components/ha-circular-progress";
import { createCloseHeading } from "../../../../../components/ha-dialog";
@@ -25,9 +26,13 @@ class DialogZWaveJSRemoveNode extends LitElement {
@state() private _node?: ZWaveJSRemovedNode;
+ @state() private _removedCallback?: () => void;
+
private _removeNodeTimeoutHandle?: number;
- private _subscribed?: Promise<() => Promise>;
+ private _subscribed?: Promise;
+
+ @state() private _error?: string;
public disconnectedCallback(): void {
super.disconnectedCallback();
@@ -38,6 +43,10 @@ class DialogZWaveJSRemoveNode extends LitElement {
params: ZWaveJSRemoveNodeDialogParams
): Promise {
this.entry_id = params.entry_id;
+ this._removedCallback = params.removedCallback;
+ if (params.skipConfirmation) {
+ this._startExclusion();
+ }
}
protected render() {
@@ -107,6 +116,11 @@ class DialogZWaveJSRemoveNode extends LitElement {
"ui.panel.config.zwave_js.remove_node.exclusion_failed"
)}
+ ${this._error
+ ? html`
+ ${this._error}
+ `
+ : ""}
@@ -143,13 +157,17 @@ class DialogZWaveJSRemoveNode extends LitElement {
if (!this.hass) {
return;
}
- this._subscribed = this.hass.connection.subscribeMessage(
- (message) => this._handleMessage(message),
- {
+ this._subscribed = this.hass.connection
+ .subscribeMessage((message) => this._handleMessage(message), {
type: "zwave_js/remove_node",
entry_id: this.entry_id,
- }
- );
+ })
+ .catch((err) => {
+ this._status = "failed";
+ this._error = err.message;
+ return () => {};
+ });
+ this._status = "started";
this._removeNodeTimeoutHandle = window.setTimeout(
() => this._unsubscribe(),
120000
@@ -174,6 +192,9 @@ class DialogZWaveJSRemoveNode extends LitElement {
this._status = "finished";
this._node = message.node;
this._unsubscribe();
+ if (this._removedCallback) {
+ this._removedCallback();
+ }
}
}
diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-node.ts
index ac76e6dbc8e1..ac5fe5b0633f 100644
--- a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-node.ts
+++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-node.ts
@@ -2,6 +2,8 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
export interface ZWaveJSRemoveNodeDialogParams {
entry_id: string;
+ skipConfirmation?: boolean;
+ removedCallback?: () => void;
}
export const loadRemoveNodeDialog = () =>
diff --git a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
index 16f00a7178ac..1ba3a0ba5fb7 100644
--- a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
+++ b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
@@ -36,8 +36,6 @@ import {
fetchZwaveProvisioningEntries,
InclusionState,
setZwaveDataCollectionPreference,
- stopZwaveExclusion,
- stopZwaveInclusion,
subscribeZwaveControllerStatistics,
ZWaveJSClient,
ZWaveJSControllerStatisticsUpdatedMessage,
@@ -83,7 +81,17 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
protected firstUpdated() {
if (this.hass) {
- this._fetchData();
+ this._fetchData().then(() => {
+ if (this._status === "connected") {
+ const inclusion_state = this._network?.controller.inclusion_state;
+ // show dialog if inclusion/exclusion is already in progress
+ if (inclusion_state === InclusionState.Including) {
+ this._addNodeClicked();
+ } else if (inclusion_state === InclusionState.Excluding) {
+ this._removeNodeClicked();
+ }
+ }
+ });
}
}
@@ -126,31 +134,6 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
.path=${mdiRefresh}
.label=${this.hass!.localize("ui.common.refresh")}
>
- ${this._network &&
- this._status === "connected" &&
- (this._network?.controller.inclusion_state ===
- InclusionState.Including ||
- this._network?.controller.inclusion_state ===
- InclusionState.Excluding)
- ? html`
-
- ${this.hass.localize(
- `ui.panel.config.zwave_js.common.in_progress_inclusion_exclusion`
- )}
-
-
-
- `
- : ""}
${this._network
? html`
@@ -593,6 +576,9 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
private async _removeNodeClicked() {
showZWaveJSRemoveNodeDialog(this, {
entry_id: this.configEntryId!,
+ skipConfirmation:
+ this._network?.controller.inclusion_state === InclusionState.Excluding,
+ removedCallback: () => this._fetchData(),
});
}
@@ -602,16 +588,6 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
});
}
- private async _cancelInclusion() {
- stopZwaveInclusion(this.hass!, this.configEntryId!);
- await this._fetchData();
- }
-
- private async _cancelExclusion() {
- stopZwaveExclusion(this.hass!, this.configEntryId!);
- await this._fetchData();
- }
-
private _dataCollectionToggled(ev) {
setZwaveDataCollectionPreference(
this.hass!,
From ed9cd95c0bf03585ebdd0060bc6dffb674052827 Mon Sep 17 00:00:00 2001
From: Petar Petrov
Date: Wed, 30 Oct 2024 09:46:07 +0100
Subject: [PATCH 2/2] tweak code style
---
.../zwave_js/dialog-zwave_js-remove-node.ts | 10 +++---
.../zwave_js/zwave_js-config-dashboard.ts | 31 +++++++++----------
2 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
index 0e9f62f5ac2d..1c579b42e554 100644
--- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
+++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-remove-node.ts
@@ -76,7 +76,7 @@ class DialogZWaveJSRemoveNode extends LitElement {
)}
`
- : ``}
+ : nothing}
${this._status === "started"
? html`
@@ -102,7 +102,7 @@ class DialogZWaveJSRemoveNode extends LitElement {
)}
`
- : ``}
+ : nothing}
${this._status === "failed"
? html`
@@ -120,14 +120,14 @@ class DialogZWaveJSRemoveNode extends LitElement {
? html`
${this._error}
`
- : ""}
+ : nothing}
${this.hass.localize("ui.common.close")}
`
- : ``}
+ : nothing}
${this._status === "finished"
? html`
@@ -148,7 +148,7 @@ class DialogZWaveJSRemoveNode extends LitElement {
${this.hass.localize("ui.common.close")}
`
- : ``}
+ : nothing}
`;
}
diff --git a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
index 1ba3a0ba5fb7..66f9e1fadd07 100644
--- a/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
+++ b/src/panels/config/integrations/integration-panels/zwave_js/zwave_js-config-dashboard.ts
@@ -79,19 +79,18 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
@state()
private _statistics?: ZWaveJSControllerStatisticsUpdatedMessage;
- protected firstUpdated() {
+ protected async firstUpdated() {
if (this.hass) {
- this._fetchData().then(() => {
- if (this._status === "connected") {
- const inclusion_state = this._network?.controller.inclusion_state;
- // show dialog if inclusion/exclusion is already in progress
- if (inclusion_state === InclusionState.Including) {
- this._addNodeClicked();
- } else if (inclusion_state === InclusionState.Excluding) {
- this._removeNodeClicked();
- }
+ await this._fetchData();
+ if (this._status === "connected") {
+ const inclusion_state = this._network?.controller.inclusion_state;
+ // show dialog if inclusion/exclusion is already in progress
+ if (inclusion_state === InclusionState.Including) {
+ this._addNodeClicked();
+ } else if (inclusion_state === InclusionState.Excluding) {
+ this._removeNodeClicked();
}
- });
+ }
}
}
@@ -176,11 +175,11 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
`ui.panel.config.zwave_js.dashboard.not_ready`,
{ count: notReadyDevices }
)})`
- : ""}
+ : nothing}
`
- : ``}
+ : nothing}
@@ -207,7 +206,7 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
)}
`
- : ""}
+ : nothing}
@@ -447,7 +446,7 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) {
`
- : ``}
+ : nothing}
`
- : ""}`;
+ : nothing}`;
}
private _handleBack(): void {