diff --git a/src/data/zha.ts b/src/data/zha.ts index f5a67dbb12..8c50b82f3c 100644 --- a/src/data/zha.ts +++ b/src/data/zha.ts @@ -7,8 +7,19 @@ export interface ZHADeviceEntity extends HassEntity { }; } -export interface ZHAEntities { - [key: string]: HassEntity[]; +export interface ZHAEntityReference extends HassEntity { + name: string; +} + +export interface ZHADevice { + name: string; + ieee: string; + manufacturer: string; + model: string; + quirk_applied: boolean; + quirk_class: string; + entities: ZHAEntityReference[]; + manufacturer_code: number; } export interface Attribute { @@ -19,6 +30,7 @@ export interface Attribute { export interface Cluster { name: string; id: number; + endpoint_id: number; type: string; } @@ -29,7 +41,8 @@ export interface Command { } export interface ReadAttributeServiceData { - entity_id: string; + ieee: string; + endpoint_id: number; cluster_id: number; cluster_type: string; attribute: number; @@ -41,64 +54,60 @@ export const reconfigureNode = ( ieeeAddress: string ): Promise => hass.callWS({ - type: "zha/nodes/reconfigure", + type: "zha/devices/reconfigure", ieee: ieeeAddress, }); export const fetchAttributesForCluster = ( hass: HomeAssistant, - entityId: string, ieeeAddress: string, + endpointId: number, clusterId: number, clusterType: string ): Promise => hass.callWS({ - type: "zha/entities/clusters/attributes", - entity_id: entityId, + type: "zha/devices/clusters/attributes", ieee: ieeeAddress, + endpoint_id: endpointId, cluster_id: clusterId, cluster_type: clusterType, }); +export const fetchDevices = (hass: HomeAssistant): Promise => + hass.callWS({ + type: "zha/devices", + }); + export const readAttributeValue = ( hass: HomeAssistant, data: ReadAttributeServiceData ): Promise => { return hass.callWS({ ...data, - type: "zha/entities/clusters/attributes/value", + type: "zha/devices/clusters/attributes/value", }); }; export const fetchCommandsForCluster = ( hass: HomeAssistant, - entityId: string, ieeeAddress: string, + endpointId: number, clusterId: number, clusterType: string ): Promise => hass.callWS({ - type: "zha/entities/clusters/commands", - entity_id: entityId, + type: "zha/devices/clusters/commands", ieee: ieeeAddress, + endpoint_id: endpointId, cluster_id: clusterId, cluster_type: clusterType, }); export const fetchClustersForZhaNode = ( hass: HomeAssistant, - entityId: string, ieeeAddress: string ): Promise => hass.callWS({ - type: "zha/entities/clusters", - entity_id: entityId, + type: "zha/devices/clusters", ieee: ieeeAddress, }); - -export const fetchEntitiesForZhaNode = ( - hass: HomeAssistant -): Promise => - hass.callWS({ - type: "zha/entities", - }); diff --git a/src/panels/config/zha/ha-config-zha.ts b/src/panels/config/zha/ha-config-zha.ts index 23ae151636..1ab743c6c6 100755 --- a/src/panels/config/zha/ha-config-zha.ts +++ b/src/panels/config/zha/ha-config-zha.ts @@ -14,11 +14,7 @@ import { Cluster } from "../../../data/zha"; import "../../../layouts/ha-app-layout"; import { haStyle } from "../../../resources/ha-style"; import { HomeAssistant } from "../../../types"; -import { - ZHAClusterSelectedParams, - ZHAEntitySelectedParams, - ZHANodeSelectedParams, -} from "./types"; +import { ZHAClusterSelectedParams, ZHANodeSelectedParams } from "./types"; import "./zha-cluster-attributes"; import "./zha-cluster-commands"; import "./zha-network"; @@ -29,14 +25,12 @@ export class HaConfigZha extends LitElement { public isWide?: boolean; private _selectedNode?: HassEntity; private _selectedCluster?: Cluster; - private _selectedEntity?: HassEntity; static get properties(): PropertyDeclarations { return { hass: {}, isWide: {}, _selectedCluster: {}, - _selectedEntity: {}, _selectedNode: {}, }; } @@ -64,7 +58,6 @@ export class HaConfigZha extends LitElement { .hass="${this.hass}" @zha-cluster-selected="${this._onClusterSelected}" @zha-node-selected="${this._onNodeSelected}" - @zha-entity-selected="${this._onEntitySelected}" > ${this._selectedCluster ? html` @@ -72,7 +65,6 @@ export class HaConfigZha extends LitElement { .isWide="${this.isWide}" .hass="${this.hass}" .selectedNode="${this._selectedNode}" - .selectedEntity="${this._selectedEntity}" .selectedCluster="${this._selectedCluster}" > @@ -80,7 +72,6 @@ export class HaConfigZha extends LitElement { .isWide="${this.isWide}" .hass="${this.hass}" .selectedNode="${this._selectedNode}" - .selectedEntity="${this._selectedEntity}" .selectedCluster="${this._selectedCluster}" > ` @@ -100,13 +91,6 @@ export class HaConfigZha extends LitElement { ): void { this._selectedNode = selectedNodeEvent.detail.node; this._selectedCluster = undefined; - this._selectedEntity = undefined; - } - - private _onEntitySelected( - selectedEntityEvent: HASSDomEvent - ): void { - this._selectedEntity = selectedEntityEvent.detail.entity; } static get styles(): CSSResult[] { diff --git a/src/panels/config/zha/types.ts b/src/panels/config/zha/types.ts index 23bc9f74d7..1f006964d7 100644 --- a/src/panels/config/zha/types.ts +++ b/src/panels/config/zha/types.ts @@ -1,4 +1,3 @@ -import { HassEntity } from "home-assistant-js-websocket"; import { ZHADeviceEntity, Cluster } from "../../../data/zha"; export interface PickerTarget extends EventTarget { @@ -17,7 +16,8 @@ export interface ChangeEvent { } export interface SetAttributeServiceData { - entity_id: string; + ieee: string; + endpoint_id: number; cluster_id: number; cluster_type: string; attribute: number; @@ -26,17 +26,14 @@ export interface SetAttributeServiceData { } export interface IssueCommandServiceData { - entity_id: string; + ieee: string; + endpoint_id: number; cluster_id: number; cluster_type: string; command: number; command_type: string; } -export interface ZHAEntitySelectedParams { - entity: HassEntity; -} - export interface ZHANodeSelectedParams { node: ZHADeviceEntity; } diff --git a/src/panels/config/zha/zha-cluster-attributes.ts b/src/panels/config/zha/zha-cluster-attributes.ts index d19354cdcd..165e336dbe 100644 --- a/src/panels/config/zha/zha-cluster-attributes.ts +++ b/src/panels/config/zha/zha-cluster-attributes.ts @@ -10,7 +10,6 @@ import { import "@polymer/paper-button/paper-button"; import "@polymer/paper-card/paper-card"; import "@polymer/paper-icon-button/paper-icon-button"; -import { HassEntity } from "home-assistant-js-websocket"; import "../../../components/buttons/ha-call-service-button"; import "../../../components/ha-service-description"; import { @@ -19,7 +18,7 @@ import { fetchAttributesForCluster, ReadAttributeServiceData, readAttributeValue, - ZHADeviceEntity, + ZHADevice, } from "../../../data/zha"; import { haStyle } from "../../../resources/ha-style"; import { HomeAssistant } from "../../../types"; @@ -34,8 +33,7 @@ export class ZHAClusterAttributes extends LitElement { public hass?: HomeAssistant; public isWide?: boolean; public showHelp: boolean; - public selectedNode?: HassEntity; - public selectedEntity?: ZHADeviceEntity; + public selectedNode?: ZHADevice; public selectedCluster?: Cluster; private _attributes: Attribute[]; private _selectedAttributeIndex: number; @@ -57,7 +55,6 @@ export class ZHAClusterAttributes extends LitElement { isWide: {}, showHelp: {}, selectedNode: {}, - selectedEntity: {}, selectedCluster: {}, _attributes: {}, _selectedAttributeIndex: {}, @@ -172,49 +169,54 @@ export class ZHAClusterAttributes extends LitElement { } private async _fetchAttributesForCluster(): Promise { - if (this.selectedEntity && this.selectedCluster && this.hass) { + if (this.selectedNode && this.selectedCluster && this.hass) { this._attributes = await fetchAttributesForCluster( this.hass, - this.selectedEntity!.entity_id, - this.selectedEntity!.device_info!.identifiers[0][1], + this.selectedNode!.ieee, + this.selectedCluster!.endpoint_id, this.selectedCluster!.id, this.selectedCluster!.type ); + this._attributes.sort((a, b) => { + return a.name.localeCompare(b.name); + }); } } private _computeReadAttributeServiceData(): | ReadAttributeServiceData | undefined { - if (!this.selectedEntity || !this.selectedCluster || !this.selectedNode) { + if (!this.selectedCluster || !this.selectedNode) { return; } return { - entity_id: this.selectedEntity!.entity_id, + ieee: this.selectedNode!.ieee, + endpoint_id: this.selectedCluster!.endpoint_id, cluster_id: this.selectedCluster!.id, cluster_type: this.selectedCluster!.type, attribute: this._attributes[this._selectedAttributeIndex].id, manufacturer: this._manufacturerCodeOverride ? parseInt(this._manufacturerCodeOverride as string, 10) - : this.selectedNode!.attributes.manufacturer_code, + : this.selectedNode!.manufacturer_code, }; } private _computeSetAttributeServiceData(): | SetAttributeServiceData | undefined { - if (!this.selectedEntity || !this.selectedCluster || !this.selectedNode) { + if (!this.selectedCluster || !this.selectedNode) { return; } return { - entity_id: this.selectedEntity!.entity_id, + ieee: this.selectedNode!.ieee, + endpoint_id: this.selectedCluster!.endpoint_id, cluster_id: this.selectedCluster!.id, cluster_type: this.selectedCluster!.type, attribute: this._attributes[this._selectedAttributeIndex].id, value: this._attributeValue, manufacturer: this._manufacturerCodeOverride ? parseInt(this._manufacturerCodeOverride as string, 10) - : this.selectedNode!.attributes.manufacturer_code, + : this.selectedNode!.manufacturer_code, }; } @@ -306,8 +308,7 @@ export class ZHAClusterAttributes extends LitElement { [hidden] { display: none; } - - `, + `, ]; } } diff --git a/src/panels/config/zha/zha-cluster-commands.ts b/src/panels/config/zha/zha-cluster-commands.ts index 398a7ff3d6..14429982f9 100644 --- a/src/panels/config/zha/zha-cluster-commands.ts +++ b/src/panels/config/zha/zha-cluster-commands.ts @@ -8,14 +8,13 @@ import { css, } from "lit-element"; import "@polymer/paper-card/paper-card"; -import { HassEntity } from "home-assistant-js-websocket"; import "../../../components/buttons/ha-call-service-button"; import "../../../components/ha-service-description"; import { Cluster, Command, fetchCommandsForCluster, - ZHADeviceEntity, + ZHADevice, } from "../../../data/zha"; import { haStyle } from "../../../resources/ha-style"; import { HomeAssistant } from "../../../types"; @@ -29,8 +28,7 @@ import { export class ZHAClusterCommands extends LitElement { public hass?: HomeAssistant; public isWide?: boolean; - public selectedNode?: HassEntity; - public selectedEntity?: ZHADeviceEntity; + public selectedNode?: ZHADevice; public selectedCluster?: Cluster; private _showHelp: boolean; private _commands: Command[]; @@ -50,7 +48,6 @@ export class ZHAClusterCommands extends LitElement { hass: {}, isWide: {}, selectedNode: {}, - selectedEntity: {}, selectedCluster: {}, _showHelp: {}, _commands: {}, @@ -146,25 +143,29 @@ export class ZHAClusterCommands extends LitElement { } private async _fetchCommandsForCluster(): Promise { - if (this.selectedEntity && this.selectedCluster && this.hass) { + if (this.selectedNode && this.selectedCluster && this.hass) { this._commands = await fetchCommandsForCluster( this.hass, - this.selectedEntity!.entity_id, - this.selectedEntity!.device_info!.identifiers[0][1], + this.selectedNode!.ieee, + this.selectedCluster!.endpoint_id, this.selectedCluster!.id, this.selectedCluster!.type ); + this._commands.sort((a, b) => { + return a.name.localeCompare(b.name); + }); } } private _computeIssueClusterCommandServiceData(): | IssueCommandServiceData | undefined { - if (!this.selectedEntity || !this.selectedCluster) { + if (!this.selectedNode || !this.selectedCluster) { return; } return { - entity_id: this.selectedEntity!.entity_id, + ieee: this.selectedNode!.ieee, + endpoint_id: this.selectedCluster!.endpoint_id, cluster_id: this.selectedCluster!.id, cluster_type: this.selectedCluster!.type, command: this._commands[this._selectedCommandIndex].id, @@ -257,8 +258,7 @@ export class ZHAClusterCommands extends LitElement { [hidden] { display: none; } - - `, + `, ]; } } diff --git a/src/panels/config/zha/zha-clusters.ts b/src/panels/config/zha/zha-clusters.ts index d580cc49c6..c45772c510 100644 --- a/src/panels/config/zha/zha-clusters.ts +++ b/src/panels/config/zha/zha-clusters.ts @@ -11,11 +11,7 @@ import "@polymer/paper-card/paper-card"; import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/buttons/ha-call-service-button"; import "../../../components/ha-service-description"; -import { - Cluster, - fetchClustersForZhaNode, - ZHADeviceEntity, -} from "../../../data/zha"; +import { Cluster, fetchClustersForZhaNode, ZHADevice } from "../../../data/zha"; import { haStyle } from "../../../resources/ha-style"; import { HomeAssistant } from "../../../types"; import "../ha-config-section"; @@ -31,14 +27,16 @@ declare global { } const computeClusterKey = (cluster: Cluster): string => { - return `${cluster.name} (id: ${cluster.id}, type: ${cluster.type})`; + return `${cluster.name} (Endpoint id: ${cluster.endpoint_id}, Id: ${ + cluster.id + }, Type: ${cluster.type})`; }; export class ZHAClusters extends LitElement { public hass?: HomeAssistant; public isWide?: boolean; public showHelp: boolean; - public selectedEntity?: ZHADeviceEntity; + public selectedDevice?: ZHADevice; private _selectedClusterIndex: number; private _clusters: Cluster[]; @@ -54,14 +52,14 @@ export class ZHAClusters extends LitElement { hass: {}, isWide: {}, showHelp: {}, - selectedEntity: {}, + selectedDevice: {}, _selectedClusterIndex: {}, _clusters: {}, }; } protected updated(changedProperties: PropertyValues): void { - if (changedProperties.has("selectedEntity")) { + if (changedProperties.has("selectedDevice")) { this._clusters = []; this._selectedClusterIndex = -1; fireEvent(this, "zha-cluster-selected", { @@ -103,9 +101,11 @@ export class ZHAClusters extends LitElement { if (this.hass) { this._clusters = await fetchClustersForZhaNode( this.hass, - this.selectedEntity!.entity_id, - this.selectedEntity!.device_info!.identifiers[0][1] + this.selectedDevice!.ieee ); + this._clusters.sort((a, b) => { + return a.name.localeCompare(b.name); + }); } } diff --git a/src/panels/config/zha/zha-device-card.ts b/src/panels/config/zha/zha-device-card.ts new file mode 100644 index 0000000000..449f26d956 --- /dev/null +++ b/src/panels/config/zha/zha-device-card.ts @@ -0,0 +1,118 @@ +import { + html, + LitElement, + property, + TemplateResult, + CSSResult, + css, +} from "lit-element"; +import "@polymer/paper-item/paper-icon-item"; +import "@polymer/paper-item/paper-item-body"; +import "@polymer/paper-card/paper-card"; +import "@polymer/paper-dropdown-menu/paper-dropdown-menu"; +import "@polymer/paper-item/paper-item"; +import "@polymer/paper-listbox/paper-listbox"; +import { fireEvent } from "../../../common/dom/fire_event"; +import { haStyle } from "../../../resources/ha-style"; +import { HomeAssistant } from "../../../types"; + +import "../../../components/entity/state-badge"; +import { ZHADevice } from "../../../data/zha"; + +class ZHADeviceCard extends LitElement { + @property() public hass?: HomeAssistant; + @property() public narrow?: boolean; + @property() public device?: ZHADevice; + + protected render(): TemplateResult | void { + return html` + +
+
+
IEEE:
+
${this.device!.ieee}
+
Quirk applied:
+
${this.device!.quirk_applied}
+
Quirk:
+
${this.device!.quirk_class}
+
+
+ +
+ ${this.device!.entities.map( + (entity) => html` + + + +
${entity.name}
+
${entity.entity_id}
+
+
+ ` + )} +
+
+ `; + } + + private _openMoreInfo(ev: MouseEvent): void { + fireEvent(this, "hass-more-info", { + entityId: (ev.currentTarget as any).entity.entity_id, + }); + } + + static get styles(): CSSResult[] { + return [ + haStyle, + css` + :host(:not([narrow])) .device-entities { + max-height: 225px; + overflow: auto; + } + paper-card { + flex: 1 0 100%; + padding-bottom: 10px; + min-width: 0; + } + .device { + width: 30%; + } + .label { + font-weight: bold; + } + .info { + color: var(--secondary-text-color); + font-weight: bold; + } + dl dt { + float: left; + width: 100px; + text-align: left; + } + dt dd { + margin-left: 10px; + text-align: left; + } + paper-icon-item { + cursor: pointer; + padding-top: 4px; + padding-bottom: 4px; + } + `, + ]; + } +} + +declare global { + interface HTMLElementTagNameMap { + "zha-device-card": ZHADeviceCard; + } +} + +customElements.define("zha-device-card", ZHADeviceCard); diff --git a/src/panels/config/zha/zha-entities.ts b/src/panels/config/zha/zha-entities.ts deleted file mode 100644 index 9b6f373f07..0000000000 --- a/src/panels/config/zha/zha-entities.ts +++ /dev/null @@ -1,170 +0,0 @@ -import { - html, - LitElement, - PropertyDeclarations, - PropertyValues, - TemplateResult, - CSSResult, - css, -} from "lit-element"; -import "@polymer/paper-button/paper-button"; -import "@polymer/paper-item/paper-item"; -import "@polymer/paper-listbox/paper-listbox"; -import { HassEntity } from "home-assistant-js-websocket"; -import { fireEvent } from "../../../common/dom/fire_event"; -import { fetchEntitiesForZhaNode } from "../../../data/zha"; -import { haStyle } from "../../../resources/ha-style"; -import { HomeAssistant } from "../../../types"; -import { ItemSelectedEvent } from "./types"; - -declare global { - // for fire event - interface HASSDomEvents { - "zha-entity-selected": { - entity?: HassEntity; - }; - } -} - -export class ZHAEntities extends LitElement { - public hass?: HomeAssistant; - public showHelp?: boolean; - public selectedNode?: HassEntity; - private _selectedEntityIndex: number; - private _entities: HassEntity[]; - - constructor() { - super(); - this._entities = []; - this._selectedEntityIndex = -1; - } - - static get properties(): PropertyDeclarations { - return { - hass: {}, - showHelp: {}, - selectedNode: {}, - _selectedEntityIndex: {}, - _entities: {}, - }; - } - - protected updated(changedProperties: PropertyValues): void { - if (changedProperties.has("selectedNode")) { - this._entities = []; - this._selectedEntityIndex = -1; - fireEvent(this, "zha-entity-selected", { - entity: undefined, - }); - this._fetchEntitiesForZhaNode(); - } - super.update(changedProperties); - } - - protected render(): TemplateResult | void { - return html` -
- - - ${this._entities.map( - (entry) => html` - ${entry.entity_id} - ` - )} - - -
- ${this.showHelp - ? html` -
- Select entity to view per-entity options -
- ` - : ""} - ${this._selectedEntityIndex !== -1 - ? html` -
- Entity Information -
- ` - : ""} - `; - } - - private async _fetchEntitiesForZhaNode(): Promise { - if (this.hass) { - const fetchedEntities = await fetchEntitiesForZhaNode(this.hass); - this._entities = fetchedEntities[this.selectedNode!.attributes.ieee]; - } - } - - private _selectedEntityChanged(event: ItemSelectedEvent): void { - this._selectedEntityIndex = event.target!.selected; - fireEvent(this, "zha-entity-selected", { - entity: this._entities[this._selectedEntityIndex], - }); - } - - private _showEntityInformation(): void { - fireEvent(this, "hass-more-info", { - entityId: this._entities[this._selectedEntityIndex].entity_id, - }); - } - - static get styles(): CSSResult[] { - return [ - haStyle, - css` - .flex { - -ms-flex: 1 1 0.000000001px; - -webkit-flex: 1; - flex: 1; - -webkit-flex-basis: 0.000000001px; - flex-basis: 0.000000001px; - } - - .node-picker { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-direction: row; - -webkit-flex-direction: row; - flex-direction: row; - -ms-flex-align: center; - -webkit-align-items: center; - align-items: center; - padding-left: 28px; - padding-right: 28px; - padding-bottom: 10px; - } - .actions { - border-top: 1px solid #e8e8e8; - padding: 5px 16px; - position: relative; - } - .actions paper-button:not([disabled]) { - color: var(--primary-color); - font-weight: 500; - } - .helpText { - color: grey; - padding: 16px; - } - `, - ]; - } -} - -declare global { - interface HTMLElementTagNameMap { - "zha-entities": ZHAEntities; - } -} - -customElements.define("zha-entities", ZHAEntities); diff --git a/src/panels/config/zha/zha-network.ts b/src/panels/config/zha/zha-network.ts index bbd70a1629..55cb4a4da3 100644 --- a/src/panels/config/zha/zha-network.ts +++ b/src/panels/config/zha/zha-network.ts @@ -102,8 +102,7 @@ export class ZHANetwork extends LitElement { [hidden] { display: none; } - - `, + `, ]; } } diff --git a/src/panels/config/zha/zha-node.ts b/src/panels/config/zha/zha-node.ts index 2c2a680b10..1dd11c8c0a 100644 --- a/src/panels/config/zha/zha-node.ts +++ b/src/panels/config/zha/zha-node.ts @@ -4,6 +4,7 @@ import { PropertyDeclarations, TemplateResult, CSSResult, + PropertyValues, css, } from "lit-element"; import "@polymer/paper-button/paper-button"; @@ -11,29 +12,22 @@ import "@polymer/paper-card/paper-card"; import "@polymer/paper-icon-button/paper-icon-button"; import "@polymer/paper-item/paper-item"; import "@polymer/paper-listbox/paper-listbox"; -import { HassEntity } from "home-assistant-js-websocket"; -import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event"; -import computeStateName from "../../../common/entity/compute_state_name"; -import sortByName from "../../../common/entity/states_sort_by_name"; +import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/buttons/ha-call-service-button"; import "../../../components/ha-service-description"; import { haStyle } from "../../../resources/ha-style"; import { HomeAssistant } from "../../../types"; import "../ha-config-section"; -import { - ItemSelectedEvent, - NodeServiceData, - ZHAEntitySelectedParams, -} from "./types"; +import { ItemSelectedEvent, NodeServiceData } from "./types"; import "./zha-clusters"; -import "./zha-entities"; -import { reconfigureNode } from "../../../data/zha"; +import "./zha-device-card"; +import { reconfigureNode, fetchDevices, ZHADevice } from "../../../data/zha"; declare global { // for fire event interface HASSDomEvents { "zha-node-selected": { - node?: HassEntity; + node?: ZHADevice; }; } } @@ -43,10 +37,9 @@ export class ZHANode extends LitElement { public isWide?: boolean; private _showHelp: boolean; private _selectedNodeIndex: number; - private _selectedNode?: HassEntity; - private _selectedEntity?: HassEntity; + private _selectedNode?: ZHADevice; private _serviceData?: {}; - private _nodes: HassEntity[]; + private _nodes: ZHADevice[]; constructor() { super(); @@ -62,13 +55,31 @@ export class ZHANode extends LitElement { _showHelp: {}, _selectedNodeIndex: {}, _selectedNode: {}, + _entities: {}, _serviceData: {}, - _selectedEntity: {}, + _nodes: {}, }; } + public firstUpdated(changedProperties: PropertyValues): void { + super.firstUpdated(changedProperties); + if (this._nodes.length === 0) { + this._fetchDevices(); + } + this.addEventListener("hass-service-called", (ev) => + this.serviceCalled(ev) + ); + } + + protected serviceCalled(ev): void { + // Check if this is for us + if (ev.detail.success && ev.detail.service === "remove") { + this._selectedNodeIndex = -1; + this._fetchDevices(); + } + } + protected render(): TemplateResult | void { - this._nodes = this._computeNodes(this.hass); return html`
@@ -94,12 +105,11 @@ export class ZHANode extends LitElement { ${this._nodes.map( (entry) => html` - ${this._computeSelectCaption(entry)} + ${entry.name} ` )} @@ -112,9 +122,18 @@ export class ZHANode extends LitElement {
` : ""} + ${this._selectedNodeIndex !== -1 + ? html` + + ` + : ""} ${this._selectedNodeIndex !== -1 ? this._renderNodeActions() : ""} - ${this._selectedNodeIndex !== -1 ? this._renderEntities() : ""} - ${this._selectedEntity ? this._renderClusters() : ""} + ${this._selectedNode ? this._renderClusters() : ""}
`; @@ -123,9 +142,6 @@ export class ZHANode extends LitElement { private _renderNodeActions(): TemplateResult { return html`
- Node Information Reconfigure Node @@ -158,22 +174,11 @@ export class ZHANode extends LitElement { `; } - private _renderEntities(): TemplateResult { - return html` - - `; - } - private _renderClusters(): TemplateResult { return html` `; @@ -186,50 +191,26 @@ export class ZHANode extends LitElement { private _selectedNodeChanged(event: ItemSelectedEvent): void { this._selectedNodeIndex = event!.target!.selected; this._selectedNode = this._nodes[this._selectedNodeIndex]; - this._selectedEntity = undefined; fireEvent(this, "zha-node-selected", { node: this._selectedNode }); this._serviceData = this._computeNodeServiceData(); } private async _onReconfigureNodeClick(): Promise { if (this.hass) { - await reconfigureNode(this.hass, this._selectedNode!.attributes.ieee); + await reconfigureNode(this.hass, this._selectedNode!.ieee); } } - private _showNodeInformation(): void { - fireEvent(this, "hass-more-info", { - entityId: this._selectedNode!.entity_id, - }); - } - private _computeNodeServiceData(): NodeServiceData { return { - ieee_address: this._selectedNode!.attributes.ieee, + ieee_address: this._selectedNode!.ieee, }; } - private _computeSelectCaption(stateObj: HassEntity): string { - return ( - computeStateName(stateObj) + " (Node:" + stateObj.attributes.ieee + ")" - ); - } - - private _computeNodes(hass?: HomeAssistant): HassEntity[] { - if (hass) { - return Object.keys(hass.states) - .map((key) => hass.states[key]) - .filter((ent) => ent.entity_id.match("zha[.]")) - .sort(sortByName); - } else { - return []; - } - } - - private _onEntitySelected( - entitySelectedEvent: HASSDomEvent - ): void { - this._selectedEntity = entitySelectedEvent.detail.entity; + private async _fetchDevices() { + this._nodes = (await fetchDevices(this.hass!)).sort((a, b) => { + return a.name.localeCompare(b.name); + }); } static get styles(): CSSResult[] { @@ -287,6 +268,17 @@ export class ZHANode extends LitElement { padding-bottom: 10px; } + .card { + box-sizing: border-box; + display: flex; + flex: 1 0 300px; + min-width: 0; + max-width: 600px; + padding-left: 28px; + padding-right: 28px; + padding-bottom: 10px; + } + ha-service-description { display: block; color: grey;