From 7358faf88eee0011e1b1e2839b1ad1b9155faf91 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Wed, 25 May 2022 12:49:25 -0400 Subject: [PATCH] Update zwave_js/network_status WS API (#12735) --- src/data/zwave_js.ts | 19 +++++++++++++++---- .../zwave_js/device-actions.ts | 1 - .../zwave_js/dialog-zwave_js-heal-network.ts | 7 +++---- .../zwave_js/dialog-zwave_js-heal-node.ts | 13 ++++--------- .../show-dialog-zwave_js-heal-node.ts | 1 - .../zwave_js/zwave_js-config-dashboard.ts | 2 +- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index b920f1f9de..11bcefa4cb 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -301,12 +301,23 @@ export const migrateZwave = ( export const fetchZwaveNetworkStatus = ( hass: HomeAssistant, - entry_id: string -): Promise => - hass.callWS({ + device_or_entry_id: { + device_id?: string; + entry_id?: string; + } +): Promise => { + if (device_or_entry_id.device_id && device_or_entry_id.entry_id) { + throw new Error("Only one of device or entry ID should be supplied."); + } + if (!device_or_entry_id.device_id && !device_or_entry_id.entry_id) { + throw new Error("Either device or entry ID should be supplied."); + } + return hass.callWS({ type: "zwave_js/network_status", - entry_id, + device_id: device_or_entry_id.device_id, + entry_id: device_or_entry_id.entry_id, }); +}; export const fetchZwaveDataCollectionStatus = ( hass: HomeAssistant, 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 7992a3a767..004a2a6c95 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 @@ -52,7 +52,6 @@ export const getZwaveDeviceActions = async ( label: hass.localize("ui.panel.config.zwave_js.device_info.heal_node"), action: () => showZWaveJSHealNodeDialog(el, { - entry_id: entryId, device: device, }), }, diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-network.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-network.ts index f99b073869..8044a6b366 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-network.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-network.ts @@ -202,10 +202,9 @@ class DialogZWaveJSHealNetwork extends LitElement { if (!this.hass) { return; } - const network: ZWaveJSNetwork = await fetchZwaveNetworkStatus( - this.hass!, - this.entry_id! - ); + const network: ZWaveJSNetwork = await fetchZwaveNetworkStatus(this.hass!, { + entry_id: this.entry_id!, + }); if (network.controller.is_heal_network_active) { this._status = "started"; this._subscribed = subscribeHealZwaveNetworkProgress( diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-node.ts index a418183a24..5615d78d40 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-heal-node.ts @@ -22,8 +22,6 @@ import { ZWaveJSHealNodeDialogParams } from "./show-dialog-zwave_js-heal-node"; class DialogZWaveJSHealNode extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; - @state() private entry_id?: string; - @state() private device?: DeviceRegistryEntry; @state() private _status?: string; @@ -31,13 +29,11 @@ class DialogZWaveJSHealNode extends LitElement { @state() private _error?: string; public showDialog(params: ZWaveJSHealNodeDialogParams): void { - this.entry_id = params.entry_id; this.device = params.device; this._fetchData(); } public closeDialog(): void { - this.entry_id = undefined; this._status = undefined; this.device = undefined; this._error = undefined; @@ -46,7 +42,7 @@ class DialogZWaveJSHealNode extends LitElement { } protected render(): TemplateResult { - if (!this.entry_id || !this.device) { + if (!this.device) { return html``; } @@ -202,10 +198,9 @@ class DialogZWaveJSHealNode extends LitElement { if (!this.hass) { return; } - const network: ZWaveJSNetwork = await fetchZwaveNetworkStatus( - this.hass!, - this.entry_id! - ); + const network: ZWaveJSNetwork = await fetchZwaveNetworkStatus(this.hass!, { + device_id: this.device!.id, + }); if (network.controller.is_heal_network_active) { this._status = "network-healing"; } diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node.ts index 39bb062709..047cebdc47 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node.ts @@ -2,7 +2,6 @@ import { fireEvent } from "../../../../../common/dom/fire_event"; import { DeviceRegistryEntry } from "../../../../../data/device_registry"; export interface ZWaveJSHealNodeDialogParams { - entry_id: string; device: DeviceRegistryEntry; } 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 63b59efae1..6acef7a572 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 @@ -573,7 +573,7 @@ class ZWaveJSConfigDashboard extends SubscribeMixin(LitElement) { const [network, dataCollectionStatus, provisioningEntries] = await Promise.all([ - fetchZwaveNetworkStatus(this.hass!, this.configEntryId), + fetchZwaveNetworkStatus(this.hass!, { entry_id: this.configEntryId }), fetchZwaveDataCollectionStatus(this.hass!, this.configEntryId), fetchZwaveProvisioningEntries(this.hass!, this.configEntryId), ]);