Fix ZHA neighbor table in the manage device dialog (#14236)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
David F. Mulcahey 2022-10-31 11:20:49 -04:00 committed by GitHub
parent 2e988bf5c3
commit 42386c7dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 31 deletions

View File

@ -36,6 +36,8 @@ export interface Neighbor {
ieee: string; ieee: string;
nwk: string; nwk: string;
lqi: string; lqi: string;
depth: string;
relationship: string;
} }
export interface ZHADeviceEndpoint { export interface ZHADeviceEndpoint {

View File

@ -27,7 +27,7 @@ import "./zha-cluster-commands";
import "./zha-manage-clusters"; import "./zha-manage-clusters";
import "./zha-device-binding"; import "./zha-device-binding";
import "./zha-group-binding"; import "./zha-group-binding";
import "./zha-device-children"; import "./zha-device-neighbors";
import "./zha-device-signature"; import "./zha-device-signature";
import { import {
Tab, Tab,
@ -179,10 +179,11 @@ class DialogZHAManageZigbeeDevice extends LitElement {
></zha-device-zigbee-info> ></zha-device-zigbee-info>
` `
: html` : html`
<zha-device-children <zha-device-neighbors
.hass=${this.hass} .hass=${this.hass}
.device=${this._device} .device=${this._device}
></zha-device-children> .narrow=${!this.large}
></zha-device-neighbors>
` `
)} )}
</div> </div>
@ -221,7 +222,7 @@ class DialogZHAManageZigbeeDevice extends LitElement {
device && device &&
(device.device_type === "Router" || device.device_type === "Coordinator") (device.device_type === "Router" || device.device_type === "Coordinator")
) { ) {
tabs.push("children"); tabs.push("neighbors");
} }
return tabs; return tabs;

View File

@ -1,7 +1,7 @@
import { fireEvent } from "../../../../../common/dom/fire_event"; import { fireEvent } from "../../../../../common/dom/fire_event";
import { ZHADevice } from "../../../../../data/zha"; import { ZHADevice } from "../../../../../data/zha";
export type Tab = "clusters" | "bindings" | "signature" | "children"; export type Tab = "clusters" | "bindings" | "signature" | "neighbors";
export interface ZHAManageZigbeeDeviceDialogParams { export interface ZHAManageZigbeeDeviceDialogParams {
device: ZHADevice; device: ZHADevice;

View File

@ -16,12 +16,16 @@ export interface DeviceRowData extends DataTableRowData {
id: string; id: string;
name: string; name: string;
lqi: number; lqi: number;
depth: number;
relationship: string;
} }
@customElement("zha-device-children") @customElement("zha-device-neighbors")
class ZHADeviceChildren extends LitElement { class ZHADeviceNeighbors extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property({ type: Boolean }) public narrow!: boolean;
@property() public device: ZHADevice | undefined; @property() public device: ZHADevice | undefined;
@state() private _devices: Map<string, ZHADevice> | undefined; @state() private _devices: Map<string, ZHADevice> | undefined;
@ -33,20 +37,22 @@ class ZHADeviceChildren extends LitElement {
} }
} }
private _deviceChildren = memoizeOne( private _deviceNeighbors = memoizeOne(
( (
device: ZHADevice | undefined, device: ZHADevice | undefined,
devices: Map<string, ZHADevice> | undefined devices: Map<string, ZHADevice> | undefined
) => { ) => {
const outputDevices: DeviceRowData[] = []; const outputDevices: DeviceRowData[] = [];
if (device && devices) { if (device && devices) {
device.neighbors.forEach((child) => { device.neighbors.forEach((neighbor) => {
const zhaDevice: ZHADevice | undefined = devices.get(child.ieee); const zhaDevice: ZHADevice | undefined = devices.get(neighbor.ieee);
if (zhaDevice) { if (zhaDevice) {
outputDevices.push({ outputDevices.push({
name: zhaDevice.user_given_name || zhaDevice.name, name: zhaDevice.user_given_name || zhaDevice.name,
id: zhaDevice.device_reg_id, id: zhaDevice.device_reg_id,
lqi: parseInt(child.lqi), lqi: parseInt(neighbor.lqi),
depth: parseInt(neighbor.depth),
relationship: neighbor.relationship,
}); });
} }
}); });
@ -55,22 +61,57 @@ class ZHADeviceChildren extends LitElement {
} }
); );
private _columns: DataTableColumnContainer = { private _columns = memoizeOne(
(narrow: boolean): DataTableColumnContainer =>
narrow
? {
name: { name: {
title: "Name", title: this.hass.localize("ui.panel.config.zha.neighbors.name"),
sortable: true, sortable: true,
filterable: true, filterable: true,
direction: "asc", direction: "asc",
grows: true, grows: true,
}, },
lqi: { lqi: {
title: "LQI", title: this.hass.localize("ui.panel.config.zha.neighbors.lqi"),
sortable: true, sortable: true,
filterable: true, filterable: true,
type: "numeric", type: "numeric",
width: "75px", width: "75px",
}, },
}; }
: {
name: {
title: this.hass.localize("ui.panel.config.zha.neighbors.name"),
sortable: true,
filterable: true,
direction: "asc",
grows: true,
},
lqi: {
title: this.hass.localize("ui.panel.config.zha.neighbors.lqi"),
sortable: true,
filterable: true,
type: "numeric",
width: "75px",
},
relationship: {
title: this.hass.localize(
"ui.panel.config.zha.neighbors.relationship"
),
sortable: true,
filterable: true,
width: "150px",
},
depth: {
title: this.hass.localize("ui.panel.config.zha.neighbors.depth"),
sortable: true,
filterable: true,
type: "numeric",
width: "75px",
},
}
);
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.device) { if (!this.device) {
@ -85,8 +126,8 @@ class ZHADeviceChildren extends LitElement {
></ha-circular-progress>` ></ha-circular-progress>`
: html`<ha-data-table : html`<ha-data-table
.hass=${this.hass} .hass=${this.hass}
.columns=${this._columns} .columns=${this._columns(this.narrow)}
.data=${this._deviceChildren(this.device, this._devices)} .data=${this._deviceNeighbors(this.device, this._devices)}
auto-height auto-height
.dir=${computeRTLDirection(this.hass)} .dir=${computeRTLDirection(this.hass)}
.searchLabel=${this.hass.localize( .searchLabel=${this.hass.localize(
@ -111,6 +152,6 @@ class ZHADeviceChildren extends LitElement {
declare global { declare global {
interface HTMLElementTagNameMap { interface HTMLElementTagNameMap {
"zha-device-children": ZHADeviceChildren; "zha-device-neighbors": ZHADeviceNeighbors;
} }
} }

View File

@ -1024,7 +1024,7 @@
"clusters": "Clusters", "clusters": "Clusters",
"bindings": "Bindings", "bindings": "Bindings",
"signature": "Signature", "signature": "Signature",
"children": "Children" "neighbors": "Neighbors"
} }
}, },
"zha_device_info": { "zha_device_info": {
@ -3247,6 +3247,12 @@
"unbind_button_label": "Unbind Group", "unbind_button_label": "Unbind Group",
"bind_button_help": "Bind the selected group to the selected device clusters.", "bind_button_help": "Bind the selected group to the selected device clusters.",
"unbind_button_help": "Unbind the selected group from the selected device clusters." "unbind_button_help": "Unbind the selected group from the selected device clusters."
},
"neighbors": {
"name": "Name",
"lqi": "LQI",
"relationship": "Relationship",
"depth": "Depth"
} }
}, },
"zwave_js": { "zwave_js": {