Fix zwave js handling multiple config entries

This commit is contained in:
Bram Kragten 2022-05-09 14:43:27 +02:00
parent 6faa3eb848
commit e5f64bb26d
No known key found for this signature in database
GPG Key ID: FBE2DFDB363EF55B
3 changed files with 50 additions and 36 deletions

View File

@ -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;
}
}

View File

@ -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(

View File

@ -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 {
></ha-device-actions-zwave_js>
`);
}
return templates;
}
private async _showSettings() {