From b55c7edd70b16e9ec51064492ed2ef70d3c294a0 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 17 Feb 2022 04:41:12 -0500 Subject: [PATCH] Make zwave_js config panel inclusion state aware (#11556) Co-authored-by: Bram Kragten --- src/data/zwave_js.ts | 42 ++++++++++++- .../zwave_js/zwave_js-config-dashboard.ts | 61 +++++++++++++++---- src/translations/en.json | 4 +- 3 files changed, 92 insertions(+), 15 deletions(-) diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index ab02e4acf8..1cc8653752 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -2,6 +2,19 @@ import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { HomeAssistant } from "../types"; import { DeviceRegistryEntry } from "./device_registry"; +export enum InclusionState { + /** The controller isn't doing anything regarding inclusion. */ + Idle, + /** The controller is waiting for a node to be included. */ + Including, + /** The controller is waiting for a node to be excluded. */ + Excluding, + /** The controller is busy including or excluding a node. */ + Busy, + /** The controller listening for SmartStart nodes to announce themselves. */ + SmartStart, +} + export const enum InclusionStrategy { /** * Always uses Security S2 if supported, otherwise uses Security S0 for certain devices which don't work without encryption and uses no encryption otherwise. @@ -106,16 +119,33 @@ export interface ZWaveJSNetwork { } export interface ZWaveJSClient { - state: string; + state: "connected" | "disconnected"; ws_server_url: string; server_version: string; driver_version: string; } export interface ZWaveJSController { - home_id: string; - nodes: number[]; + home_id: number; + library_version: string; + type: number; + own_node_id: number; + is_secondary: boolean; + is_using_home_id_from_other_network: boolean; + is_sis_present: boolean; + was_real_primary: boolean; + is_static_update_controller: boolean; + is_slave: boolean; + serial_api_version: string; + manufacturer_id: number; + product_id: number; + product_type: number; + supported_function_types: number[]; + suc_node_id: number; + supports_timers: boolean; is_heal_network_active: boolean; + inclusion_state: InclusionState; + nodes: number[]; } export interface ZWaveJSNodeStatus { @@ -309,6 +339,12 @@ export const stopZwaveInclusion = (hass: HomeAssistant, entry_id: string) => entry_id, }); +export const stopZwaveExclusion = (hass: HomeAssistant, entry_id: string) => + hass.callWS({ + type: "zwave_js/stop_exclusion", + entry_id, + }); + export const zwaveGrantSecurityClasses = ( hass: HomeAssistant, entry_id: string, 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 82ef64d6b3..1b1521f32f 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 @@ -19,7 +19,11 @@ import { fetchZwaveNetworkStatus, fetchZwaveNodeStatus, fetchZwaveProvisioningEntries, + InclusionState, setZwaveDataCollectionPreference, + stopZwaveExclusion, + stopZwaveInclusion, + ZWaveJSClient, ZWaveJSNetwork, ZWaveJSNodeStatus, ZwaveJSProvisioningEntry, @@ -60,7 +64,7 @@ class ZWaveJSConfigDashboard extends LitElement { @state() private _provisioningEntries?: ZwaveJSProvisioningEntry[]; - @state() private _status = "unknown"; + @state() private _status?: ZWaveJSClient["state"]; @state() private _icon = mdiCircle; @@ -107,13 +111,38 @@ class ZWaveJSConfigDashboard extends LitElement { "ui.panel.config.zwave_js.dashboard.introduction" )} + ${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`
- ${this._status === "connecting" + ${this._status === "disconnected" ? html`` @@ -121,13 +150,13 @@ class ZWaveJSConfigDashboard extends LitElement { `}
- ${this._status !== "connecting" + ${this._status !== "disconnected" ? html`
${this.hass.localize( @@ -207,7 +236,9 @@ class ZWaveJSConfigDashboard extends LitElement {
${this.hass.localize( "ui.panel.config.zwave_js.common.remove_node" @@ -215,16 +246,13 @@ class ZWaveJSConfigDashboard extends LitElement { ${this.hass.localize( "ui.panel.config.zwave_js.common.heal_network" )} - + ${this.hass.localize( "ui.panel.config.zwave_js.common.reconfigure_server" )} @@ -272,10 +300,11 @@ class ZWaveJSConfigDashboard extends LitElement { .label=${this.hass.localize( "ui.panel.config.zwave_js.common.add_node" )} - .disabled=${this._status === "connecting"} extended ?rtl=${computeRTL(this.hass)} @click=${this._addNodeClicked} + .disabled=${this._status !== "connected" || + this._network?.controller.inclusion_state !== InclusionState.Idle} > @@ -412,6 +441,16 @@ class ZWaveJSConfigDashboard extends 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!, diff --git a/src/translations/en.json b/src/translations/en.json index df7573c610..c5c1b5feab 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2956,7 +2956,9 @@ "add_node": "Add device", "remove_node": "Remove device", "reconfigure_server": "Re-configure Server", - "heal_network": "Heal Network" + "heal_network": "Heal Network", + "in_progress_inclusion_exclusion": "Z-Wave JS is searching for devices", + "cancel_inclusion_exclusion": "Stop Searching" }, "dashboard": { "header": "Manage your Z-Wave Network",