diff --git a/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js.ts b/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js.ts index 5d9a4205e6..217b81501d 100644 --- a/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js.ts +++ b/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-actions-zwave_js.ts @@ -20,6 +20,7 @@ import { HomeAssistant } from "../../../../../../types"; import { showZWaveJSReinterviewNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node"; import { showZWaveJSHealNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node"; import { showZWaveJSRemoveFailedNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-failed-node"; +import { getConfigEntries } from "../../../../../../data/config_entries"; @customElement("ha-device-actions-zwave_js") export class HaDeviceActionsZWaveJS extends LitElement { @@ -33,24 +34,35 @@ export class HaDeviceActionsZWaveJS extends LitElement { @state() private _node?: ZWaveJSNodeStatus; - protected updated(changedProperties: PropertyValues) { + public willUpdate(changedProperties: PropertyValues) { if (changedProperties.has("device")) { - const identifiers: ZWaveJSNodeIdentifiers | undefined = - getZwaveJsIdentifiersFromDevice(this.device); - if (!identifiers) { - return; - } - this._nodeId = identifiers.node_id; - this._entryId = this.device.config_entries[0]; - this._fetchNodeDetails(); } } protected async _fetchNodeDetails() { - if (!this._nodeId || !this._entryId) { + this._node = undefined; + + const identifiers: ZWaveJSNodeIdentifiers | undefined = + getZwaveJsIdentifiersFromDevice(this.device); + if (!identifiers) { return; } + this._nodeId = identifiers.node_id; + + const configEntries = await getConfigEntries(this.hass, { + domain: "zwave_js", + }); + + const configEntry = configEntries.find((entry) => + this.device.config_entries.includes(entry.entry_id) + ); + + if (!configEntry) { + return; + } + + this._entryId = configEntry.entry_id; this._node = await fetchZwaveNodeStatus( this.hass, @@ -137,3 +149,9 @@ export class HaDeviceActionsZWaveJS extends LitElement { ]; } } + +declare global { + interface HTMLElementTagNameMap { + "ha-device-actions-zwave_js": HaDeviceActionsZWaveJS; + } +} diff --git a/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-info-zwave_js.ts b/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-info-zwave_js.ts index 78d56a0b1b..6e27f98c9a 100644 --- a/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-info-zwave_js.ts +++ b/src/panels/config/devices/device-detail/integration-elements/zwave_js/ha-device-info-zwave_js.ts @@ -39,40 +39,38 @@ export class HaDeviceInfoZWaveJS extends LitElement { @state() private _node?: ZWaveJSNodeStatus; - protected updated(changedProperties: PropertyValues) { + public willUpdate(changedProperties: PropertyValues) { if (changedProperties.has("device")) { - const identifiers: ZWaveJSNodeIdentifiers | undefined = - getZwaveJsIdentifiersFromDevice(this.device); - if (!identifiers) { - return; - } - this._nodeId = identifiers.node_id; - this._entryId = this.device.config_entries[0]; - this._fetchNodeDetails(); } } protected async _fetchNodeDetails() { - if (!this._nodeId || !this._entryId) { + this._node = undefined; + + const identifiers: ZWaveJSNodeIdentifiers | undefined = + getZwaveJsIdentifiersFromDevice(this.device); + if (!identifiers) { return; } + this._nodeId = identifiers.node_id; const configEntries = await getConfigEntries(this.hass, { domain: "zwave_js", }); - let zwaveJsConfEntries = 0; - for (const entry of configEntries) { - if (zwaveJsConfEntries) { - this._multipleConfigEntries = true; - } - if (entry.entry_id === this._entryId) { - this._configEntry = entry; - } - if (this._configEntry && this._multipleConfigEntries) { - break; - } - zwaveJsConfEntries++; + + this._configEntry = configEntries.find((entry) => + this.device.config_entries.includes(entry.entry_id) + ); + + if (!this._configEntry) { + return; + } + + this._entryId = this._configEntry.entry_id; + + if (configEntries.length > 1) { + this._multipleConfigEntries = true; } this._node = await fetchZwaveNodeStatus( diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index 91863e1af1..d7434a47d0 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -895,13 +895,12 @@ export class HaConfigDevicePage extends LitElement { } private _renderIntegrationInfo( - device, + device: DeviceRegistryEntry, integrations: ConfigEntry[], deviceInfo: TemplateResult[], deviceActions: (string | TemplateResult)[] - ): TemplateResult[] { + ) { const domains = integrations.map((int) => int.domain); - const templates: TemplateResult[] = []; if (domains.includes("mqtt")) { import( "./device-detail/integration-elements/mqtt/ha-device-actions-mqtt" @@ -949,7 +948,6 @@ export class HaConfigDevicePage extends LitElement { > `); } - return templates; } private async _showSettings() {