Add Z-Wave device info to OZW device pages (#6508)

* Add basic device info to devices page for OZW devices

* Remove unused HassEntity

* connection -> identifier

* async fetch

* Cleanup fetch call
This commit is contained in:
Charles Garwood 2020-08-03 12:53:41 -04:00 committed by GitHub
parent 7bcbed80d7
commit b81d823602
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 140 additions and 2 deletions

21
src/data/ozw.ts Normal file
View File

@ -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<OZWDevice> =>
hass.callWS({
type: "ozw/node_status",
ozw_instance: ozw_instance,
node_id: node_id,
});

View File

@ -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`
<h4>
${this.hass.localize("ui.panel.config.ozw.device_info.zwave_info")}
</h4>
<div>
${this.hass.localize("ui.panel.config.ozw.common.node_id")}:
${this._ozwDevice.node_id}
</div>
<div>
${this.hass.localize("ui.panel.config.ozw.device_info.stage")}:
${this._ozwDevice.node_query_stage}
</div>
<div>
${this.hass.localize("ui.panel.config.ozw.common.ozw_instance")}:
${this._ozwDevice.ozw_instance}
</div>
<div>
${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")}
</div>
`;
}
static get styles(): CSSResult[] {
return [
haStyle,
css`
h4 {
margin-bottom: 4px;
}
div {
word-break: break-all;
margin-top: 2px;
}
`,
];
}
}

View File

@ -501,6 +501,15 @@ export class HaConfigDevicePage extends LitElement {
</div> </div>
`); `);
} }
if (integrations.includes("ozw")) {
import("./device-detail/integration-elements/ozw/ha-device-info-ozw");
templates.push(html`
<ha-device-info-ozw
.hass=${this.hass}
.device=${device}
></ha-device-info-ozw>
`);
}
if (integrations.includes("zha")) { if (integrations.includes("zha")) {
import("./device-detail/integration-elements/zha/ha-device-actions-zha"); import("./device-detail/integration-elements/zha/ha-device-actions-zha");
import("./device-detail/integration-elements/zha/ha-device-info-zha"); import("./device-detail/integration-elements/zha/ha-device-info-zha");

View File

@ -539,7 +539,10 @@
"sidebar_toggle": "Sidebar Toggle" "sidebar_toggle": "Sidebar Toggle"
}, },
"panel": { "panel": {
"calendar": { "my_calendars": "My Calendars", "today": "Today" }, "calendar": {
"my_calendars": "My Calendars",
"today": "Today"
},
"config": { "config": {
"header": "Configure Home Assistant", "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.", "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", "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.", "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": { "picker": {
"headers": { "name": "Name", "group": "Group", "system": "System" } "headers": {
"name": "Name",
"group": "Group",
"system": "System"
}
}, },
"editor": { "editor": {
"caption": "View user", "caption": "View user",
@ -1611,6 +1618,18 @@
"stop_listening": "Stop listening", "stop_listening": "Stop listening",
"message_received": "Message {id} received on {topic} at {time}:" "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": { "zha": {
"button": "Configure", "button": "Configure",
"header": "Configure Zigbee Home Automation", "header": "Configure Zigbee Home Automation",