From eda4dde2975b93f7cb3aa646df321a8a5e4cd632 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 02:46:14 -0400 Subject: [PATCH 01/20] Add zwave_js device statistics --- src/data/zwave_js.ts | 48 +++ .../zwave_js/device-actions.ts | 10 + .../dialog-zwave_js-node-statistics.ts | 364 ++++++++++++++++++ .../show-dialog-zwave_js-node-statistics.ts | 20 + src/translations/en.json | 68 +++- 5 files changed, 509 insertions(+), 1 deletion(-) create mode 100644 src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts create mode 100644 src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics.ts diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index 11bcefa4cbc4..ac856503168c 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -244,6 +244,41 @@ export interface ZWaveJSControllerStatisticsUpdatedMessage { timeout_callback: number; } +export enum RssiError { + NotAvailable = 127, + ReceiverSaturated = 126, + NoSignalDetected = 125, +} + +export enum ProtocolDataRate { + ZWave_9k6 = 0x01, + ZWave_40k = 0x02, + ZWave_100k = 0x03, + LongRange_100k = 0x04, +} + +export interface ZWaveJSNodeStatisticsUpdatedMessage { + event: "statistics updated"; + source: "node"; + commands_tx: number; + commands_rx: number; + commands_dropped_tx: number; + commands_dropped_rx: number; + timeout_response: number; + rtt: number | null; + rssi: number | null; + lwr: ZWaveJSRouteStatistics | null; + nlwr: ZWaveJSRouteStatistics | null; +} + +export interface ZWaveJSRouteStatistics { + protocol_data_rate: number; + repeaters: string[]; + rssi: number | null; + repeater_rssi: number[]; + route_failed_between: [string, string] | null; +} + export interface ZWaveJSRemovedNode { node_id: number; manufacturer: string; @@ -597,6 +632,19 @@ export const subscribeZwaveControllerStatistics = ( } ); +export const subscribeZwaveNodeStatistics = ( + hass: HomeAssistant, + device_id: string, + callbackFunction: (message: ZWaveJSNodeStatisticsUpdatedMessage) => void +): Promise => + hass.connection.subscribeMessage( + (message: any) => callbackFunction(message), + { + type: "zwave_js/subscribe_node_statistics", + device_id, + } + ); + export const getZwaveJsIdentifiersFromDevice = ( device: DeviceRegistryEntry ): ZWaveJSNodeIdentifiers | undefined => { 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 004a2a6c9590..82694f4fa761 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 @@ -3,6 +3,7 @@ import { DeviceRegistryEntry } from "../../../../../../data/device_registry"; import { fetchZwaveNodeStatus } from "../../../../../../data/zwave_js"; import type { HomeAssistant } from "../../../../../../types"; import { showZWaveJSHealNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node"; +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 type { DeviceAction } from "../../../ha-config-device-page"; @@ -64,5 +65,14 @@ export const getZwaveDeviceActions = async ( device_id: device.id, }), }, + { + label: hass.localize( + "ui.panel.config.zwave_js.device_info.node_statistics" + ), + action: () => + showZWaveJSNodeStatisticsDialog(el, { + device: device, + }), + }, ]; }; diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts new file mode 100644 index 000000000000..4deaefac113c --- /dev/null +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -0,0 +1,364 @@ +import { UnsubscribeFunc } from "home-assistant-js-websocket"; +import "@material/mwc-list/mwc-list"; +import "@material/mwc-list/mwc-list-item"; +import "../../../../../components/ha-expansion-panel"; +import "../../../../../components/ha-help-tooltip"; +import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; +import { customElement, property, state } from "lit/decorators"; +import { fireEvent } from "../../../../../common/dom/fire_event"; +import { + DeviceRegistryEntry, + computeDeviceName, + subscribeDeviceRegistry, +} from "../../../../../data/device_registry"; +import { + subscribeZwaveNodeStatistics, + ProtocolDataRate, + ZWaveJSNodeStatisticsUpdatedMessage, + ZWaveJSRouteStatistics, + RssiError, +} from "../../../../../data/zwave_js"; +import { haStyleDialog } from "../../../../../resources/styles"; +import { HomeAssistant } from "../../../../../types"; +import { ZWaveJSNodeStatisticsDialogParams } from "./show-dialog-zwave_js-node-statistics"; +import { createCloseHeading } from "../../../../../components/ha-dialog"; + +@customElement("dialog-zwave_js-node-statistics") +class DialogZWaveJSNodeStatistics extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @state() private device?: DeviceRegistryEntry; + + @state() private _nodeStatistics?: ZWaveJSNodeStatisticsUpdatedMessage; + + @state() private _devices?: DeviceRegistryEntry[]; + + private _subscribedNodeStatistics?: Promise; + + private _subscribedDeviceRegistry?: UnsubscribeFunc; + + public showDialog(params: ZWaveJSNodeStatisticsDialogParams): void { + this.device = params.device; + this._subscribeNodeStatistics(); + this._subscribeDeviceRegistry(); + } + + public closeDialog(): void { + this._nodeStatistics = undefined; + this.device = undefined; + + this._unsubscribe(); + + fireEvent(this, "dialog-closed", { dialog: this.localName }); + } + + protected render(): TemplateResult { + if (!this.device) { + return html``; + } + + const workingRoutes: [ZWaveJSRouteStatistics | null | undefined, string][] = + [ + [this._nodeStatistics?.lwr, "lwr"], + [this._nodeStatistics?.nlwr, "nlwr"], + ]; + + return html` + + + + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_tx.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_tx.tooltip" + )} + + ${this._nodeStatistics?.commands_tx} + + + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_rx.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_rx.tooltip" + )} + + ${this._nodeStatistics?.commands_rx} + + + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_dropped_tx.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_dropped_tx.tooltip" + )} + + ${this._nodeStatistics?.commands_dropped_tx} + + + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_dropped_rx.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.commands_dropped_rx.tooltip" + )} + + ${this._nodeStatistics?.commands_dropped_rx} + + + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.timeout_response.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.timeout_response.tooltip" + )} + + ${this._nodeStatistics?.timeout_response} + + ${this._nodeStatistics?.rtt + ? html` + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.rtt.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.rtt.tooltip" + )} + + ${this._nodeStatistics?.rtt} + ` + : ``} + ${this._nodeStatistics?.rssi + ? html` + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.rssi.label" + )} + + ${this.hass.localize( + "ui.panel.config.zwave_js.node_statistics.rssi.tooltip" + )} + + ${this._computeRSSI(this._nodeStatistics?.rssi, false)} + ` + : ``} + + ${workingRoutes.map(([wrValue, wrLabel]) => { + if (wrValue) { + const wrRepeaterRSSIMap: { [key: string]: string } = {}; + for (let idx = 0; idx < wrValue.repeaters.length; idx++) { + wrRepeaterRSSIMap[ + this._computeDeviceNameById(wrValue.repeaters[idx]) + ] = this._computeRSSI(wrValue.repeater_rssi[idx], true); + } + + return html` + +
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.protocol_data_rate.label" + )} + + ${this.hass.localize( + `ui.panel.config.zwave_js.protocol_data_rate.${ + ProtocolDataRate[wrValue.protocol_data_rate] + }` + )} +
+ ${wrValue.rssi + ? html`
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.rssi.label" + )} + + ${this._computeRSSI(wrValue.rssi, true)} +
` + : ``} + ${wrValue.route_failed_between + ? html`
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.route_failed_between.label" + )} + + ${`${this._computeDeviceNameById( + wrValue.route_failed_between[0] + )} <-> ${this._computeDeviceNameById( + wrValue.route_failed_between[1] + )}`} +
` + : ``} + ${wrValue.repeaters.length > 0 + ? html`
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.label" + )} + + ${Object.entries(wrRepeaterRSSIMap).map( + ([repeaterName, rssi]) => html` +
+ ${repeaterName}: + ${rssi} +
+ ` + )}
+
` + : ``} +
+ `; + } + return ``; + })} +
+ `; + } + + private _computeRSSI(rssi: number, includeUnit: boolean): string { + if (Object.values(RssiError).includes(rssi)) { + return this.hass.localize( + `ui.panel.config.zwave_js.rssi.rssi_error.${RssiError[rssi]}` + ); + } + if (includeUnit) { + return `${rssi} ${this.hass.localize( + "ui.panel.config.zwave_js.rssi.unit" + )}`; + } + return rssi.toString(); + } + + private _computeDeviceNameById(device_id: string): string { + if (!this._devices) { + return device_id; + } + const device = this._devices.find((dev) => dev.id === device_id); + if (!device) { + return device_id; + } + + return computeDeviceName(device, this.hass); + } + + private _subscribeNodeStatistics(): void { + if (!this.hass) { + return; + } + this._subscribedNodeStatistics = subscribeZwaveNodeStatistics( + this.hass, + this.device!.id, + (message: ZWaveJSNodeStatisticsUpdatedMessage) => { + this._nodeStatistics = message; + } + ); + } + + private _subscribeDeviceRegistry(): void { + if (!this.hass) { + return; + } + this._subscribedDeviceRegistry = subscribeDeviceRegistry( + this.hass.connection, + (devices: DeviceRegistryEntry[]) => { + this._devices = devices; + } + ); + } + + private _unsubscribe(): void { + if (this._subscribedNodeStatistics) { + this._subscribedNodeStatistics.then((unsub) => unsub()); + this._subscribedNodeStatistics = undefined; + } + if (this._subscribedDeviceRegistry) { + this._subscribedDeviceRegistry(); + this._subscribedDeviceRegistry = undefined; + } + } + + static get styles(): CSSResultGroup { + return [ + haStyleDialog, + css` + mwc-list-item { + height: 60px; + } + + .row { + display: flex; + justify-content: space-between; + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "dialog-zwave_js-node-statistics": DialogZWaveJSNodeStatistics; + } +} diff --git a/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics.ts new file mode 100644 index 000000000000..ec48d7f02c54 --- /dev/null +++ b/src/panels/config/integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics.ts @@ -0,0 +1,20 @@ +import { fireEvent } from "../../../../../common/dom/fire_event"; +import { DeviceRegistryEntry } from "../../../../../data/device_registry"; + +export interface ZWaveJSNodeStatisticsDialogParams { + device: DeviceRegistryEntry; +} + +export const loadNodeStatisticsDialog = () => + import("./dialog-zwave_js-node-statistics"); + +export const showZWaveJSNodeStatisticsDialog = ( + element: HTMLElement, + nodeStatisticsDialogParams: ZWaveJSNodeStatisticsDialogParams +): void => { + fireEvent(element, "show-dialog", { + dialogTag: "dialog-zwave_js-node-statistics", + dialogImport: loadNodeStatisticsDialog, + dialogParams: nodeStatisticsDialogParams, + }); +}; diff --git a/src/translations/en.json b/src/translations/en.json index 2d3f00c4edb2..82bb635c9bf7 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3101,7 +3101,73 @@ "highest_security": "Highest Security", "unknown": "Unknown", "zwave_plus": "Z-Wave Plus", - "zwave_plus_version": "Version {version}" + "zwave_plus_version": "Version {version}", + "node_statistics": "Show Device Statistics" + }, + "node_statistics": { + "title": "Device Statistics", + "commands_tx": { + "label": "Commands TX", + "tooltip": "# of commands successfully sent to the node" + }, + "commands_rx": { + "label": "Commands RX", + "tooltip": "# of commands received from the node, including responses to sent commands" + }, + "commands_dropped_tx": { + "label": "Commands Dropped TX", + "tooltip": "# of outgoing commands that were dropped because they could not be sent" + }, + "commands_dropped_rx": { + "label": "Commands Dropped RX", + "tooltip": "# of commands from the node that were dropped by the host" + }, + "timeout_response": { + "label": "Timeout Response", + "tooltip": "# of Get-type commands where the node's response did not come in time" + }, + "rtt": { + "label": "RTT", + "tooltip": "Average round-trip-time in ms of commands to this node" + }, + "rssi": { + "label": "RSSI", + "tooltip": "Average RSSI in dBm of frames received by this node" + }, + "lwr": "Last Working Route", + "nlwr": "Next to Last Working Route" + }, + "route_statistics": { + "protocol_data_rate": { + "label": "Protocol Data Rate", + "tooltip": "The protocol and used data rate for this route" + }, + "repeaters": { + "label": "Repeaters + RSSI", + "tooltip": "Which nodes are repeaters for this route and their RSSI" + }, + "rssi": { + "label": "RSSI", + "tooltip": "The RSSI of the ACK frame received by the controller" + }, + "route_failed_between": { + "label": "Route Failed Between", + "tooltip": "The nodes between which the transmission failed most recently" + } + }, + "rssi": { + "unit": "dBm", + "rssi_error": { + "NotAvailable": "Not Available", + "ReceiverSaturated": "Receiver Saturated", + "NoSignalDetected": "No Signal Detected" + } + }, + "protocol_data_rate": { + "ZWave_9k6": "Z-Wave 9600", + "ZWave_40k": "Z-Wave 40K", + "ZWave_100k": "Z-Wave 100K", + "LongRange_100k": "Long Range 100K" }, "node_config": { "header": "Z-Wave Device Configuration", From 625f298519a21f6a5e06e3c68a9e89d3120af068 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 02:56:45 -0400 Subject: [PATCH 02/20] tweaks --- .../dialog-zwave_js-node-statistics.ts | 25 ++++++++++++++++--- src/translations/en.json | 22 +++++++++++++--- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 4deaefac113c..57ce8a6ee738 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -193,17 +193,36 @@ class DialogZWaveJSNodeStatistics extends LitElement {
${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.protocol_data_rate.label" + "ui.panel.config.zwave_js.route_statistics.protocol.label" )} ${this.hass.localize( - `ui.panel.config.zwave_js.protocol_data_rate.${ + `ui.panel.config.zwave_js.route_statistics.protocol.protocol_data_rate.${ + ProtocolDataRate[wrValue.protocol_data_rate] + }` + )} +
+
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.data_rate.label" + )} + + ${this.hass.localize( + `ui.panel.config.zwave_js.route_statistics.data_rate.protocol_data_rate.${ ProtocolDataRate[wrValue.protocol_data_rate] }` )} Date: Thu, 26 May 2022 02:58:12 -0400 Subject: [PATCH 03/20] lower case unit --- src/translations/en.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/translations/en.json b/src/translations/en.json index dacca39bdee8..ab4611471baa 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3153,9 +3153,9 @@ "tooltip": "The used data rate for this route", "protocol_data_rate": { "ZWave_9k6": "9600", - "ZWave_40k": "40K", - "ZWave_100k": "100K", - "LongRange_100k": "100K" + "ZWave_40k": "40k", + "ZWave_100k": "100k", + "LongRange_100k": "100k" } }, "repeaters": { From daa0ad7e52978fd1d217f97efa821018171d4697 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 03:27:45 -0400 Subject: [PATCH 04/20] Use arrow icon instead of multiple characters --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 57ce8a6ee738..27dbedaf51d6 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -3,6 +3,8 @@ import "@material/mwc-list/mwc-list"; import "@material/mwc-list/mwc-list-item"; import "../../../../../components/ha-expansion-panel"; import "../../../../../components/ha-help-tooltip"; +import "../../../../../components/ha-svg-icon"; +import { mdiSwapHorizontal } from "@mdi/js"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; import { fireEvent } from "../../../../../common/dom/fire_event"; @@ -256,11 +258,12 @@ class DialogZWaveJSNodeStatistics extends LitElement { ${`${this._computeDeviceNameById( + >${this._computeDeviceNameById( wrValue.route_failed_between[0] - )} <-> ${this._computeDeviceNameById( + )}${this._computeDeviceNameById( wrValue.route_failed_between[1] - )}`}
` : ``} From f0ddf61a7dd3c5fe181fc902021fb8a83e9cf931 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 03:43:12 -0400 Subject: [PATCH 05/20] Add some padding to make table look cleaner --- .../dialog-zwave_js-node-statistics.ts | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 27dbedaf51d6..9657594c8723 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -279,12 +279,12 @@ class DialogZWaveJSNodeStatistics extends LitElement { > - ${Object.entries(wrRepeaterRSSIMap).map( ([repeaterName, rssi]) => html`
- ${repeaterName}: - ${rssi} + ${repeaterName}: + ${rssi}
` )}
Date: Thu, 26 May 2022 03:47:05 -0400 Subject: [PATCH 06/20] Remove space --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 9657594c8723..b3030e68d606 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -283,7 +283,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { >${Object.entries(wrRepeaterRSSIMap).map( ([repeaterName, rssi]) => html`
- ${repeaterName}: + ${repeaterName}: ${rssi}
` From 897bae3f2cc5f48fe225b19c8f6a48089716d626 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 18:33:39 -0400 Subject: [PATCH 07/20] Calculate on message received rather on render --- src/data/zwave_js.ts | 6 +- .../dialog-zwave_js-node-statistics.ts | 185 ++++++++++++------ src/translations/en.json | 4 +- 3 files changed, 136 insertions(+), 59 deletions(-) diff --git a/src/data/zwave_js.ts b/src/data/zwave_js.ts index ac856503168c..c3f3919e1f32 100644 --- a/src/data/zwave_js.ts +++ b/src/data/zwave_js.ts @@ -266,7 +266,7 @@ export interface ZWaveJSNodeStatisticsUpdatedMessage { commands_dropped_rx: number; timeout_response: number; rtt: number | null; - rssi: number | null; + rssi: RssiError | number | null; lwr: ZWaveJSRouteStatistics | null; nlwr: ZWaveJSRouteStatistics | null; } @@ -274,8 +274,8 @@ export interface ZWaveJSNodeStatisticsUpdatedMessage { export interface ZWaveJSRouteStatistics { protocol_data_rate: number; repeaters: string[]; - rssi: number | null; - repeater_rssi: number[]; + rssi: RssiError | number | null; + repeater_rssi: (RssiError | number)[]; route_failed_between: [string, string] | null; } diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index b3030e68d606..af4f0aadb316 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -25,15 +25,31 @@ import { HomeAssistant } from "../../../../../types"; import { ZWaveJSNodeStatisticsDialogParams } from "./show-dialog-zwave_js-node-statistics"; import { createCloseHeading } from "../../../../../components/ha-dialog"; +type WorkingRouteStatistics = + | (ZWaveJSRouteStatistics & { + repeater_rssi_table?: TemplateResult; + rssi_translated?: TemplateResult | string; + route_failed_between_translated?: [string, string]; + }) + | undefined; + @customElement("dialog-zwave_js-node-statistics") class DialogZWaveJSNodeStatistics extends LitElement { @property({ attribute: false }) public hass!: HomeAssistant; @state() private device?: DeviceRegistryEntry; - @state() private _nodeStatistics?: ZWaveJSNodeStatisticsUpdatedMessage; + @state() private _nodeStatistics?: ZWaveJSNodeStatisticsUpdatedMessage & { + rssi_translated?: TemplateResult | string; + }; + + @state() private _deviceIDsToDevices: { [key: string]: DeviceRegistryEntry } = + {}; - @state() private _devices?: DeviceRegistryEntry[]; + @state() private _workingRoutes: { + lwr: WorkingRouteStatistics; + nlwr: WorkingRouteStatistics; + } = { lwr: undefined, nlwr: undefined }; private _subscribedNodeStatistics?: Promise; @@ -41,8 +57,8 @@ class DialogZWaveJSNodeStatistics extends LitElement { public showDialog(params: ZWaveJSNodeStatisticsDialogParams): void { this.device = params.device; - this._subscribeNodeStatistics(); this._subscribeDeviceRegistry(); + this._subscribeNodeStatistics(); } public closeDialog(): void { @@ -59,12 +75,6 @@ class DialogZWaveJSNodeStatistics extends LitElement { return html``; } - const workingRoutes: [ZWaveJSRouteStatistics | null | undefined, string][] = - [ - [this._nodeStatistics?.lwr, "lwr"], - [this._nodeStatistics?.nlwr, "nlwr"], - ]; - return html` - ${this._nodeStatistics?.rtt} + ${this._nodeStatistics.rtt} ` : ``} - ${this._nodeStatistics?.rssi + ${this._nodeStatistics?.rssi_translated ? html` ${this.hass.localize( @@ -171,25 +181,16 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.rssi.tooltip" )} - ${this._computeRSSI(this._nodeStatistics?.rssi, false)} + ${this._nodeStatistics.rssi_translated} ` : ``} - ${workingRoutes.map(([wrValue, wrLabel]) => { + ${Object.entries(this._workingRoutes).map(([wrKey, wrValue]) => { if (wrValue) { - const wrRepeaterRSSIMap: { [key: string]: string } = {}; - for (let idx = 0; idx < wrValue.repeaters.length; idx++) { - wrRepeaterRSSIMap[ - this._computeDeviceNameById(wrValue.repeaters[idx]) - ] = this._computeRSSI(wrValue.repeater_rssi[idx], true); - } - return html`
@@ -230,7 +231,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { )}
- ${wrValue.rssi + ${wrValue.rssi_translated ? html`
${this.hass.localize( @@ -242,10 +243,10 @@ class DialogZWaveJSNodeStatistics extends LitElement { > - ${this._computeRSSI(wrValue.rssi, true)} + ${wrValue.rssi_translated}
` : ``} - ${wrValue.route_failed_between + ${wrValue.route_failed_between_translated ? html`
${this.hass.localize( @@ -258,16 +259,15 @@ class DialogZWaveJSNodeStatistics extends LitElement { ${this._computeDeviceNameById( - wrValue.route_failed_between[0] - )}${this._computeDeviceNameById( - wrValue.route_failed_between[1] - )}${wrValue + .route_failed_between_translated[0]}${wrValue.route_failed_between_translated[1]}
` : ``} - ${wrValue.repeaters.length > 0 + ${wrValue.repeater_rssi_table ? html`
${this.hass.localize( @@ -279,15 +279,24 @@ class DialogZWaveJSNodeStatistics extends LitElement { > - ${Object.entries(wrRepeaterRSSIMap).map( - ([repeaterName, rssi]) => html` -
- ${repeaterName}: - ${rssi} -
- ` - )}
+ ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.repeaters" + )}: + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.rssi" + )}: +
+ ${wrValue.repeater_rssi_table}
` : ``} @@ -300,27 +309,31 @@ class DialogZWaveJSNodeStatistics extends LitElement { `; } - private _computeRSSI(rssi: number, includeUnit: boolean): string { + private _computeRSSI( + rssi: number, + includeUnit: boolean + ): TemplateResult | string { if (Object.values(RssiError).includes(rssi)) { - return this.hass.localize( - `ui.panel.config.zwave_js.rssi.rssi_error.${RssiError[rssi]}` - ); + return html``; } if (includeUnit) { - return `${rssi} ${this.hass.localize( - "ui.panel.config.zwave_js.rssi.unit" - )}`; + return `${rssi} + ${this.hass.localize("ui.panel.config.zwave_js.rssi.unit")}`; } return rssi.toString(); } - private _computeDeviceNameById(device_id: string): string { - if (!this._devices) { - return device_id; + private _computeDeviceNameById(device_id: string): "unknown device" | string { + if (!this._deviceIDsToDevices) { + return "unknown device"; } - const device = this._devices.find((dev) => dev.id === device_id); + const device = this._deviceIDsToDevices[device_id]; if (!device) { - return device_id; + return "unknown device"; } return computeDeviceName(device, this.hass); @@ -335,6 +348,62 @@ class DialogZWaveJSNodeStatistics extends LitElement { this.device!.id, (message: ZWaveJSNodeStatisticsUpdatedMessage) => { this._nodeStatistics = message; + this._nodeStatistics.rssi_translated = undefined; + if (this._nodeStatistics.rssi) { + this._nodeStatistics.rssi_translated = this._computeRSSI( + this._nodeStatistics.rssi, + false + ); + } + + const workingRoutes: [ + string, + ZWaveJSRouteStatistics | null | undefined + ][] = [ + ["lwr", this._nodeStatistics?.lwr], + ["nlwr", this._nodeStatistics?.nlwr], + ]; + + workingRoutes.forEach(([wrKey, wrValue]) => { + this._workingRoutes[wrKey] = wrValue; + + if (wrValue) { + if (wrValue.rssi) { + this._workingRoutes[wrKey].rssi_translated = this._computeRSSI( + wrValue.rssi, + true + ); + } + + if (wrValue.route_failed_between) { + this._workingRoutes[wrKey].route_failed_between_translated = [ + this._computeDeviceNameById(wrValue.route_failed_between[0]), + this._computeDeviceNameById(wrValue.route_failed_between[1]), + ]; + } + + if (wrValue.repeaters) { + this._workingRoutes[ + wrKey + ].repeater_rssi_table = html` ${wrValue.repeaters.map( + (_, idx) => + html`
+ ${this._computeDeviceNameById( + wrValue.repeaters[idx] + )}: + ${this._computeRSSI( + wrValue.repeater_rssi[idx], + true + )} +
` + )}`; + } + } + }); } ); } @@ -346,7 +415,13 @@ class DialogZWaveJSNodeStatistics extends LitElement { this._subscribedDeviceRegistry = subscribeDeviceRegistry( this.hass.connection, (devices: DeviceRegistryEntry[]) => { - this._devices = devices; + Object.entries(this._deviceIDsToDevices).forEach(([_, device]) => { + if (!devices.includes(device)) + delete this._deviceIDsToDevices[device.id]; + }); + devices.forEach((device) => { + this._deviceIDsToDevices[device.id] = device; + }); } ); } diff --git a/src/translations/en.json b/src/translations/en.json index ab4611471baa..eaf313ed4814 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3160,7 +3160,9 @@ }, "repeaters": { "label": "Repeaters + RSSI", - "tooltip": "Which nodes are repeaters for this route and their RSSI" + "tooltip": "Which nodes are repeaters for this route and their RSSI", + "repeaters": "Repeater Devices", + "rssi": "RSSI" }, "rssi": { "label": "RSSI", From a7de929e7042ed5a90aa6af6e4f6cbe8ec45262c Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 19:16:36 -0400 Subject: [PATCH 08/20] Additional tweaks --- .../dialog-zwave_js-node-statistics.ts | 237 +++++++++--------- src/translations/en.json | 26 +- 2 files changed, 132 insertions(+), 131 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index af4f0aadb316..0710f2c082fa 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -185,126 +185,131 @@ class DialogZWaveJSNodeStatistics extends LitElement { ` : ``} - ${Object.entries(this._workingRoutes).map(([wrKey, wrValue]) => { - if (wrValue) { - return html` - -
- - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.protocol.label" - )} + wrValue + ? html` + +
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.protocol.label" + )} + + ${this.hass.localize( + `ui.panel.config.zwave_js.route_statistics.protocol.protocol_data_rate.${ + ProtocolDataRate[wrValue.protocol_data_rate] + }` + )} - - ${this.hass.localize( - `ui.panel.config.zwave_js.route_statistics.protocol.protocol_data_rate.${ - ProtocolDataRate[wrValue.protocol_data_rate] - }` - )} -
-
- - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.data_rate.label" - )} +
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.data_rate.label" + )} + + ${this.hass.localize( + `ui.panel.config.zwave_js.route_statistics.data_rate.protocol_data_rate.${ + ProtocolDataRate[wrValue.protocol_data_rate] + }` + )} - - ${this.hass.localize( - `ui.panel.config.zwave_js.route_statistics.data_rate.protocol_data_rate.${ - ProtocolDataRate[wrValue.protocol_data_rate] - }` - )} -
- ${wrValue.rssi_translated - ? html`
- - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.rssi.label" - )} - - ${wrValue.rssi_translated} -
` - : ``} - ${wrValue.route_failed_between_translated - ? html`
- - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.route_failed_between.label" - )} - - ${wrValue - .route_failed_between_translated[0]}${wrValue.route_failed_between_translated[1]} + ${wrValue.rssi_translated + ? html`
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.rssi.label" + )} + + ${wrValue.rssi_translated} +
` + : ``} +
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.route_failed_between.label" + )} -
` - : ``} - ${wrValue.repeater_rssi_table - ? html`
- - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.repeaters.label" - )} + + ${wrValue.route_failed_between_translated + ? html`${wrValue + .route_failed_between_translated[0]}${wrValue.route_failed_between_translated[1]}` + : this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.route_failed_between.not_applicable" )} - > - -
- ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.repeaters.repeaters" - )}: - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.repeaters.rssi" - )}: -
- ${wrValue.repeater_rssi_table}
+
+
+ + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.label" + )} -
` - : ``} - - `; - } - return ``; - })} + + ${wrValue.repeater_rssi_table + ? html`
+ ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.repeaters" + )}: + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.rssi" + )}: +
+ ${wrValue.repeater_rssi_table}
` + : html`${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.direct" + )}`} +
+ + ` + : `` + )} `; } @@ -382,7 +387,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { ]; } - if (wrValue.repeaters) { + if (wrValue.repeaters && wrValue.repeaters.length) { this._workingRoutes[ wrKey ].repeater_rssi_table = html` ${wrValue.repeaters.map( diff --git a/src/translations/en.json b/src/translations/en.json index eaf313ed4814..071862575a3a 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3152,17 +3152,18 @@ "label": "Data Rate", "tooltip": "The used data rate for this route", "protocol_data_rate": { - "ZWave_9k6": "9600", - "ZWave_40k": "40k", - "ZWave_100k": "100k", - "LongRange_100k": "100k" + "ZWave_9k6": "9.6 kbps", + "ZWave_40k": "40 kbps", + "ZWave_100k": "100 kbps", + "LongRange_100k": "100 kbps" } }, "repeaters": { "label": "Repeaters + RSSI", "tooltip": "Which nodes are repeaters for this route and their RSSI", "repeaters": "Repeater Devices", - "rssi": "RSSI" + "rssi": "RSSI", + "direct": "None, direct connection" }, "rssi": { "label": "RSSI", @@ -3170,23 +3171,18 @@ }, "route_failed_between": { "label": "Route Failed Between", - "tooltip": "The nodes between which the transmission failed most recently" + "tooltip": "The nodes between which the transmission failed most recently", + "not_applicable": "N/A" } }, "rssi": { "unit": "dBm", "rssi_error": { - "NotAvailable": "Not Available", - "ReceiverSaturated": "Receiver Saturated", - "NoSignalDetected": "No Signal Detected" + "NotAvailable": "Not available", + "ReceiverSaturated": "Receiver saturated", + "NoSignalDetected": "No signal detected" } }, - "protocol_data_rate": { - "ZWave_9k6": "Z-Wave 9600", - "ZWave_40k": "Z-Wave 40K", - "ZWave_100k": "Z-Wave 100K", - "LongRange_100k": "Long Range 100K" - }, "node_config": { "header": "Z-Wave Device Configuration", "introduction": "Manage and adjust device specific configuration parameters for the selected device", From 79008fa36beeb031712498248bd0e96170146dc9 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 21:06:48 -0400 Subject: [PATCH 09/20] Adjust styling --- .../dialog-zwave_js-node-statistics.ts | 29 ++++++++++++++----- src/translations/en.json | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 0710f2c082fa..6a8509bb1442 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -96,7 +96,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_tx.tooltip" )}
- ${this._nodeStatistics?.commands_tx} + ${this._nodeStatistics?.commands_tx} @@ -109,7 +111,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_rx.tooltip" )} - ${this._nodeStatistics?.commands_rx} + ${this._nodeStatistics?.commands_rx} @@ -122,7 +126,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_dropped_tx.tooltip" )} - ${this._nodeStatistics?.commands_dropped_tx} @@ -137,7 +141,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_dropped_rx.tooltip" )} - ${this._nodeStatistics?.commands_dropped_rx} @@ -152,7 +156,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.timeout_response.tooltip" )} - ${this._nodeStatistics?.timeout_response} + ${this._nodeStatistics?.timeout_response} ${this._nodeStatistics?.rtt ? html` @@ -166,7 +172,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.rtt.tooltip" )} - ${this._nodeStatistics.rtt} + ${this._nodeStatistics.rtt} ` : ``} ${this._nodeStatistics?.rssi_translated @@ -181,7 +189,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.rssi.tooltip" )} - ${this._nodeStatistics.rssi_translated} + ${this._nodeStatistics.rssi_translated} ` : ``} @@ -468,6 +478,11 @@ class DialogZWaveJSNodeStatistics extends LitElement { display: table-cell; padding-left: 5px; } + + .statistics { + font-size: 1em; + color: var(--primary-text-color); + } `, ]; } diff --git a/src/translations/en.json b/src/translations/en.json index 071862575a3a..6adbfbdb0289 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3161,7 +3161,7 @@ "repeaters": { "label": "Repeaters + RSSI", "tooltip": "Which nodes are repeaters for this route and their RSSI", - "repeaters": "Repeater Devices", + "repeaters": "Repeater Device", "rssi": "RSSI", "direct": "None, direct connection" }, From 27063e573b6a7febd926e512a8e8b73da43f82d3 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 21:21:33 -0400 Subject: [PATCH 10/20] Adjust size --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 6a8509bb1442..5e8ac89f2717 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -480,7 +480,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { } .statistics { - font-size: 1em; + font-size: 0.95em; color: var(--primary-text-color); } `, From d233f5fc891e50ce19ea976a0073d3c570c16925 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 26 May 2022 21:45:39 -0400 Subject: [PATCH 11/20] Tweak to reduce repeat --- .../dialog-zwave_js-node-statistics.ts | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 5e8ac89f2717..7771d70a2972 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -288,33 +288,30 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.route_statistics.repeaters.tooltip" )} > - - ${wrValue.repeater_rssi_table - ? html`
- ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.repeaters.repeaters" - )}: - ${this.hass.localize( - "ui.panel.config.zwave_js.route_statistics.repeaters.rssi" - )}: -
- ${wrValue.repeater_rssi_table}
` - : html`${this.hass.localize( + + ${wrValue.repeater_rssi_table + ? html`
+ ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.repeaters" + )}: + ${this.hass.localize( + "ui.panel.config.zwave_js.route_statistics.repeaters.rssi" + )}: +
+ ${wrValue.repeater_rssi_table}` + : html`${this.hass.localize( "ui.panel.config.zwave_js.route_statistics.repeaters.direct" - )}
`} + )}`}
` From 7632982e747f9562eb7dc3c9e781b14667719e59 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Fri, 27 May 2022 00:55:58 -0400 Subject: [PATCH 12/20] Use reference variables to make code easier to read --- .../dialog-zwave_js-node-statistics.ts | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 7771d70a2972..e0e8a4500685 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -47,9 +47,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { {}; @state() private _workingRoutes: { - lwr: WorkingRouteStatistics; - nlwr: WorkingRouteStatistics; - } = { lwr: undefined, nlwr: undefined }; + lwr?: WorkingRouteStatistics; + nlwr?: WorkingRouteStatistics; + } = {}; private _subscribedNodeStatistics?: Promise; @@ -360,7 +360,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { this.device!.id, (message: ZWaveJSNodeStatisticsUpdatedMessage) => { this._nodeStatistics = message; - this._nodeStatistics.rssi_translated = undefined; + if (this._nodeStatistics.rssi) { this._nodeStatistics.rssi_translated = this._computeRSSI( this._nodeStatistics.rssi, @@ -370,34 +370,30 @@ class DialogZWaveJSNodeStatistics extends LitElement { const workingRoutes: [ string, - ZWaveJSRouteStatistics | null | undefined + WorkingRouteStatistics | null | undefined ][] = [ ["lwr", this._nodeStatistics?.lwr], ["nlwr", this._nodeStatistics?.nlwr], ]; + this._workingRoutes = {}; workingRoutes.forEach(([wrKey, wrValue]) => { this._workingRoutes[wrKey] = wrValue; if (wrValue) { if (wrValue.rssi) { - this._workingRoutes[wrKey].rssi_translated = this._computeRSSI( - wrValue.rssi, - true - ); + wrValue.rssi_translated = this._computeRSSI(wrValue.rssi, true); } if (wrValue.route_failed_between) { - this._workingRoutes[wrKey].route_failed_between_translated = [ + wrValue.route_failed_between_translated = [ this._computeDeviceNameById(wrValue.route_failed_between[0]), this._computeDeviceNameById(wrValue.route_failed_between[1]), ]; } if (wrValue.repeaters && wrValue.repeaters.length) { - this._workingRoutes[ - wrKey - ].repeater_rssi_table = html` ${wrValue.repeaters.map( + wrValue.repeater_rssi_table = html`${wrValue.repeaters.map( (_, idx) => html`
Date: Fri, 27 May 2022 16:08:31 -0400 Subject: [PATCH 13/20] Use different selector --- .../dialog-zwave_js-node-statistics.ts | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index e0e8a4500685..df495e220b88 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -96,9 +96,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_tx.tooltip" )} - ${this._nodeStatistics?.commands_tx} + ${this._nodeStatistics?.commands_tx} @@ -111,9 +109,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_rx.tooltip" )} - ${this._nodeStatistics?.commands_rx} + ${this._nodeStatistics?.commands_rx} @@ -126,7 +122,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_dropped_tx.tooltip" )} - ${this._nodeStatistics?.commands_dropped_tx} @@ -141,7 +137,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.commands_dropped_rx.tooltip" )} - ${this._nodeStatistics?.commands_dropped_rx} @@ -156,9 +152,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.timeout_response.tooltip" )} - ${this._nodeStatistics?.timeout_response} + ${this._nodeStatistics?.timeout_response} ${this._nodeStatistics?.rtt ? html` @@ -172,9 +166,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.rtt.tooltip" )} - ${this._nodeStatistics.rtt} + ${this._nodeStatistics.rtt} ` : ``} ${this._nodeStatistics?.rssi_translated @@ -189,9 +181,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { "ui.panel.config.zwave_js.node_statistics.rssi.tooltip" )} - ${this._nodeStatistics.rssi_translated} + ${this._nodeStatistics.rssi_translated} ` : ``} @@ -472,7 +462,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { padding-left: 5px; } - .statistics { + span[slot="meta"] { font-size: 0.95em; color: var(--primary-text-color); } From 2c63a21da2bdc6d212610e77bc22c36ff5c6fee3 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 30 May 2022 17:50:19 -0400 Subject: [PATCH 14/20] Update src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts Co-authored-by: Bram Kragten --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index df495e220b88..a55748d71acf 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -413,13 +413,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { this._subscribedDeviceRegistry = subscribeDeviceRegistry( this.hass.connection, (devices: DeviceRegistryEntry[]) => { - Object.entries(this._deviceIDsToDevices).forEach(([_, device]) => { - if (!devices.includes(device)) - delete this._deviceIDsToDevices[device.id]; - }); - devices.forEach((device) => { - this._deviceIDsToDevices[device.id] = device; - }); + const devicesIdToName = {}; + devices.forEach(device => {devicesIdToName[device.id] = computeDeviceName(device, this.hass)}); + this._deviceIDsToName = devicesIdToName; } ); } From 4698671e65b256306f7cb111a0b2c5169437c5bd Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 30 May 2022 17:53:08 -0400 Subject: [PATCH 15/20] Perform update all at once so we only rerender once --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index a55748d71acf..4df988615b32 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -358,7 +358,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { ); } - const workingRoutes: [ + const workingRoutesValueMap: [ string, WorkingRouteStatistics | null | undefined ][] = [ @@ -366,9 +366,12 @@ class DialogZWaveJSNodeStatistics extends LitElement { ["nlwr", this._nodeStatistics?.nlwr], ]; - this._workingRoutes = {}; - workingRoutes.forEach(([wrKey, wrValue]) => { - this._workingRoutes[wrKey] = wrValue; + const workingRoutes: { + lwr?: WorkingRouteStatistics; + nlwr?: WorkingRouteStatistics; + } = {}; + workingRoutesValueMap.forEach(([wrKey, wrValue]) => { + workingRoutes[wrKey] = wrValue; if (wrValue) { if (wrValue.rssi) { @@ -402,6 +405,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { } } }); + this._workingRoutes = workingRoutes; } ); } @@ -414,7 +418,9 @@ class DialogZWaveJSNodeStatistics extends LitElement { this.hass.connection, (devices: DeviceRegistryEntry[]) => { const devicesIdToName = {}; - devices.forEach(device => {devicesIdToName[device.id] = computeDeviceName(device, this.hass)}); + devices.forEach((device) => { + devicesIdToName[device.id] = computeDeviceName(device, this.hass); + }); this._deviceIDsToName = devicesIdToName; } ); From 17011ac49da059881fa29ae1e6a1e82729606b58 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 30 May 2022 17:55:31 -0400 Subject: [PATCH 16/20] fix variable names --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 4df988615b32..c885983021da 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -43,7 +43,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { rssi_translated?: TemplateResult | string; }; - @state() private _deviceIDsToDevices: { [key: string]: DeviceRegistryEntry } = + @state() private _deviceIDsToName: { [key: string]: DeviceRegistryEntry } = {}; @state() private _workingRoutes: { @@ -330,10 +330,10 @@ class DialogZWaveJSNodeStatistics extends LitElement { } private _computeDeviceNameById(device_id: string): "unknown device" | string { - if (!this._deviceIDsToDevices) { + if (!this._deviceIDsToName) { return "unknown device"; } - const device = this._deviceIDsToDevices[device_id]; + const device = this._deviceIDsToName[device_id]; if (!device) { return "unknown device"; } From 587f397799ae2c5b3943d92aeeab184486114db4 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Mon, 30 May 2022 23:01:40 -0400 Subject: [PATCH 17/20] Reduce updates to _nodeStatistics to 1 --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index c885983021da..c501dad246c4 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -349,14 +349,12 @@ class DialogZWaveJSNodeStatistics extends LitElement { this.hass, this.device!.id, (message: ZWaveJSNodeStatisticsUpdatedMessage) => { - this._nodeStatistics = message; - - if (this._nodeStatistics.rssi) { - this._nodeStatistics.rssi_translated = this._computeRSSI( - this._nodeStatistics.rssi, - false - ); - } + this._nodeStatistics = { + ...message, + rssi_translated: message.rssi + ? this._computeRSSI(message.rssi, false) + : undefined, + }; const workingRoutesValueMap: [ string, From 4306c4f35cd512ec14de60fd2120587d1f849e21 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 31 May 2022 09:32:03 -0400 Subject: [PATCH 18/20] Update src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts Co-authored-by: Bram Kragten --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index c501dad246c4..775aa03dd0cf 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -338,7 +338,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { return "unknown device"; } - return computeDeviceName(device, this.hass); + return this._deviceIDsToName[device_id] || "unknown device"; } private _subscribeNodeStatistics(): void { From 66112d244397f838a26b3b2cf9015401df3a5c35 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 31 May 2022 09:32:33 -0400 Subject: [PATCH 19/20] Update src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts Co-authored-by: Bram Kragten --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 775aa03dd0cf..293e944836a3 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -43,7 +43,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { rssi_translated?: TemplateResult | string; }; - @state() private _deviceIDsToName: { [key: string]: DeviceRegistryEntry } = + @state() private _deviceIDsToName: { [key: string]: string } = {}; @state() private _workingRoutes: { From 2fda5e452c07c8c58134fe0324df2cd07a24561f Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 31 May 2022 12:25:44 -0400 Subject: [PATCH 20/20] formatting --- .../zwave_js/dialog-zwave_js-node-statistics.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts index 293e944836a3..b68eb367c0c0 100644 --- a/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts +++ b/src/panels/config/integrations/integration-panels/zwave_js/dialog-zwave_js-node-statistics.ts @@ -43,8 +43,7 @@ class DialogZWaveJSNodeStatistics extends LitElement { rssi_translated?: TemplateResult | string; }; - @state() private _deviceIDsToName: { [key: string]: string } = - {}; + @state() private _deviceIDsToName: { [key: string]: string } = {}; @state() private _workingRoutes: { lwr?: WorkingRouteStatistics;