Replace home ID with config entry title in Z-Wave device Info (#9488)

This commit is contained in:
Charles Garwood 2021-07-13 12:05:22 -04:00 committed by GitHub
parent b7fd7abe85
commit 12f7366968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 7 deletions

View File

@ -8,6 +8,10 @@ import {
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { DeviceRegistryEntry } from "../../../../../../data/device_registry";
import {
ConfigEntry,
getConfigEntries,
} from "../../../../../../data/config_entries";
import {
fetchNodeStatus,
getIdentifiersFromDevice,
@ -26,9 +30,11 @@ export class HaDeviceInfoZWaveJS extends LitElement {
@state() private _entryId?: string;
@state() private _nodeId?: number;
@state() private _configEntry?: ConfigEntry;
@state() private _homeId?: string;
@state() private _multipleConfigEntries = false;
@state() private _nodeId?: number;
@state() private _node?: ZWaveJSNode;
@ -40,7 +46,6 @@ export class HaDeviceInfoZWaveJS extends LitElement {
if (!identifiers) {
return;
}
this._homeId = identifiers.home_id;
this._nodeId = identifiers.node_id;
this._entryId = this.device.config_entries[0];
@ -52,6 +57,25 @@ export class HaDeviceInfoZWaveJS extends LitElement {
if (!this._nodeId || !this._entryId) {
return;
}
const configEntries = await getConfigEntries(this.hass);
let zwaveJsConfEntries = 0;
for (const entry of configEntries) {
if (entry.domain !== "zwave_js") {
continue;
}
if (zwaveJsConfEntries) {
this._multipleConfigEntries = true;
}
if (entry.entry_id === this._entryId) {
this._configEntry = entry;
}
if (this._configEntry && this._multipleConfigEntries) {
break;
}
zwaveJsConfEntries++;
}
this._node = await fetchNodeStatus(this.hass, this._entryId, this._nodeId);
}
@ -63,10 +87,14 @@ export class HaDeviceInfoZWaveJS extends LitElement {
<h4>
${this.hass.localize("ui.panel.config.zwave_js.device_info.zwave_info")}
</h4>
<div>
${this.hass.localize("ui.panel.config.zwave_js.common.home_id")}:
${this._homeId}
</div>
${this._multipleConfigEntries
? html`
<div>
${this.hass.localize("ui.panel.config.zwave_js.common.source")}:
${this._configEntry!.title}
</div>
`
: ""}
<div>
${this.hass.localize("ui.panel.config.zwave_js.common.node_id")}:
${this._node.node_id}

View File

@ -2593,6 +2593,7 @@
"network": "Network",
"node_id": "Node ID",
"home_id": "Home ID",
"source": "Source",
"close": "Close",
"add_node": "Add Node",
"remove_node": "Remove Node",