diff --git a/src/data/ozw.ts b/src/data/ozw.ts new file mode 100644 index 0000000000..491b0168a2 --- /dev/null +++ b/src/data/ozw.ts @@ -0,0 +1,21 @@ +import { HomeAssistant } from "../types"; + +export interface OZWDevice { + node_id: number; + node_query_stage: string; + is_awake: boolean; + is_failed: boolean; + is_zwave_plus: boolean; + ozw_instance: number; +} + +export const fetchOZWNodeStatus = ( + hass: HomeAssistant, + ozw_instance: string, + node_id: string +): Promise => + hass.callWS({ + type: "ozw/node_status", + ozw_instance: ozw_instance, + node_id: node_id, + }); diff --git a/src/panels/config/devices/device-detail/integration-elements/ozw/ha-device-info-ozw.ts b/src/panels/config/devices/device-detail/integration-elements/ozw/ha-device-info-ozw.ts new file mode 100644 index 0000000000..b82ba363f0 --- /dev/null +++ b/src/panels/config/devices/device-detail/integration-elements/ozw/ha-device-info-ozw.ts @@ -0,0 +1,89 @@ +import { + CSSResult, + customElement, + html, + LitElement, + property, + internalProperty, + TemplateResult, + css, + PropertyValues, +} from "lit-element"; +import { DeviceRegistryEntry } from "../../../../../../data/device_registry"; +import { haStyle } from "../../../../../../resources/styles"; +import { HomeAssistant } from "../../../../../../types"; +import { OZWDevice, fetchOZWNodeStatus } from "../../../../../../data/ozw"; + +@customElement("ha-device-info-ozw") +export class HaDeviceInfoOzw extends LitElement { + @property({ attribute: false }) public hass!: HomeAssistant; + + @property() public device!: DeviceRegistryEntry; + + @internalProperty() private _ozwDevice?: OZWDevice; + + protected updated(changedProperties: PropertyValues) { + if (changedProperties.has("device")) { + this._fetchNodeDetails(this.device); + } + } + + protected async _fetchNodeDetails(device) { + const ozwIdentifier = device.identifiers.find( + (identifier) => identifier[0] === "ozw" + ); + if (!ozwIdentifier) { + return; + } + const identifiers = ozwIdentifier[1].split("."); + this._ozwDevice = await fetchOZWNodeStatus( + this.hass, + identifiers[0], + identifiers[1] + ); + } + + protected render(): TemplateResult { + if (!this._ozwDevice) { + return html``; + } + return html` +

+ ${this.hass.localize("ui.panel.config.ozw.device_info.zwave_info")} +

+
+ ${this.hass.localize("ui.panel.config.ozw.common.node_id")}: + ${this._ozwDevice.node_id} +
+
+ ${this.hass.localize("ui.panel.config.ozw.device_info.stage")}: + ${this._ozwDevice.node_query_stage} +
+
+ ${this.hass.localize("ui.panel.config.ozw.common.ozw_instance")}: + ${this._ozwDevice.ozw_instance} +
+
+ ${this.hass.localize("ui.panel.config.ozw.device_info.node_failed")}: + ${this._ozwDevice.is_failed + ? this.hass.localize("ui.common.yes") + : this.hass.localize("ui.common.no")} +
+ `; + } + + static get styles(): CSSResult[] { + return [ + haStyle, + css` + h4 { + margin-bottom: 4px; + } + div { + word-break: break-all; + margin-top: 2px; + } + `, + ]; + } +} diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index bc96ae7215..ec2e67ea68 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -501,6 +501,15 @@ export class HaConfigDevicePage extends LitElement { `); } + if (integrations.includes("ozw")) { + import("./device-detail/integration-elements/ozw/ha-device-info-ozw"); + templates.push(html` + + `); + } if (integrations.includes("zha")) { import("./device-detail/integration-elements/zha/ha-device-actions-zha"); import("./device-detail/integration-elements/zha/ha-device-info-zha"); diff --git a/src/translations/en.json b/src/translations/en.json index d27eef38b7..bb692bf03b 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -539,7 +539,10 @@ "sidebar_toggle": "Sidebar Toggle" }, "panel": { - "calendar": { "my_calendars": "My Calendars", "today": "Today" }, + "calendar": { + "my_calendars": "My Calendars", + "today": "Today" + }, "config": { "header": "Configure Home Assistant", "introduction": "In this view it is possible to configure your components and Home Assistant. Not everything is possible to configure from the UI yet, but we're working on it.", @@ -1568,7 +1571,11 @@ "description": "Manage users", "users_privileges_note": "The users group is a work in progress. The user will be unable to administer the instance via the UI. We're still auditing all management API endpoints to ensure that they correctly limit access to administrators.", "picker": { - "headers": { "name": "Name", "group": "Group", "system": "System" } + "headers": { + "name": "Name", + "group": "Group", + "system": "System" + } }, "editor": { "caption": "View user", @@ -1611,6 +1618,18 @@ "stop_listening": "Stop listening", "message_received": "Message {id} received on {topic} at {time}:" }, + "ozw": { + "common": { + "zwave": "Z-Wave", + "node_id": "Node ID", + "ozw_instance": "OpenZWave Instance" + }, + "device_info": { + "zwave_info": "Z-Wave Info", + "stage": "Stage", + "node_failed": "Node Failed" + } + }, "zha": { "button": "Configure", "header": "Configure Zigbee Home Automation",