mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 21:17:47 +00:00
Fix zwave js handling multiple config entries
This commit is contained in:
parent
6faa3eb848
commit
e5f64bb26d
@ -20,6 +20,7 @@ import { HomeAssistant } from "../../../../../../types";
|
|||||||
import { showZWaveJSReinterviewNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node";
|
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 { 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 { 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")
|
@customElement("ha-device-actions-zwave_js")
|
||||||
export class HaDeviceActionsZWaveJS extends LitElement {
|
export class HaDeviceActionsZWaveJS extends LitElement {
|
||||||
@ -33,24 +34,35 @@ export class HaDeviceActionsZWaveJS extends LitElement {
|
|||||||
|
|
||||||
@state() private _node?: ZWaveJSNodeStatus;
|
@state() private _node?: ZWaveJSNodeStatus;
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
public willUpdate(changedProperties: PropertyValues) {
|
||||||
if (changedProperties.has("device")) {
|
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();
|
this._fetchNodeDetails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _fetchNodeDetails() {
|
protected async _fetchNodeDetails() {
|
||||||
if (!this._nodeId || !this._entryId) {
|
this._node = undefined;
|
||||||
|
|
||||||
|
const identifiers: ZWaveJSNodeIdentifiers | undefined =
|
||||||
|
getZwaveJsIdentifiersFromDevice(this.device);
|
||||||
|
if (!identifiers) {
|
||||||
return;
|
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._node = await fetchZwaveNodeStatus(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -137,3 +149,9 @@ export class HaDeviceActionsZWaveJS extends LitElement {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-device-actions-zwave_js": HaDeviceActionsZWaveJS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -39,40 +39,38 @@ export class HaDeviceInfoZWaveJS extends LitElement {
|
|||||||
|
|
||||||
@state() private _node?: ZWaveJSNodeStatus;
|
@state() private _node?: ZWaveJSNodeStatus;
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
public willUpdate(changedProperties: PropertyValues) {
|
||||||
if (changedProperties.has("device")) {
|
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();
|
this._fetchNodeDetails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _fetchNodeDetails() {
|
protected async _fetchNodeDetails() {
|
||||||
if (!this._nodeId || !this._entryId) {
|
this._node = undefined;
|
||||||
|
|
||||||
|
const identifiers: ZWaveJSNodeIdentifiers | undefined =
|
||||||
|
getZwaveJsIdentifiersFromDevice(this.device);
|
||||||
|
if (!identifiers) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._nodeId = identifiers.node_id;
|
||||||
|
|
||||||
const configEntries = await getConfigEntries(this.hass, {
|
const configEntries = await getConfigEntries(this.hass, {
|
||||||
domain: "zwave_js",
|
domain: "zwave_js",
|
||||||
});
|
});
|
||||||
let zwaveJsConfEntries = 0;
|
|
||||||
for (const entry of configEntries) {
|
this._configEntry = configEntries.find((entry) =>
|
||||||
if (zwaveJsConfEntries) {
|
this.device.config_entries.includes(entry.entry_id)
|
||||||
this._multipleConfigEntries = true;
|
);
|
||||||
}
|
|
||||||
if (entry.entry_id === this._entryId) {
|
if (!this._configEntry) {
|
||||||
this._configEntry = entry;
|
return;
|
||||||
}
|
}
|
||||||
if (this._configEntry && this._multipleConfigEntries) {
|
|
||||||
break;
|
this._entryId = this._configEntry.entry_id;
|
||||||
}
|
|
||||||
zwaveJsConfEntries++;
|
if (configEntries.length > 1) {
|
||||||
|
this._multipleConfigEntries = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._node = await fetchZwaveNodeStatus(
|
this._node = await fetchZwaveNodeStatus(
|
||||||
|
@ -895,13 +895,12 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _renderIntegrationInfo(
|
private _renderIntegrationInfo(
|
||||||
device,
|
device: DeviceRegistryEntry,
|
||||||
integrations: ConfigEntry[],
|
integrations: ConfigEntry[],
|
||||||
deviceInfo: TemplateResult[],
|
deviceInfo: TemplateResult[],
|
||||||
deviceActions: (string | TemplateResult)[]
|
deviceActions: (string | TemplateResult)[]
|
||||||
): TemplateResult[] {
|
) {
|
||||||
const domains = integrations.map((int) => int.domain);
|
const domains = integrations.map((int) => int.domain);
|
||||||
const templates: TemplateResult[] = [];
|
|
||||||
if (domains.includes("mqtt")) {
|
if (domains.includes("mqtt")) {
|
||||||
import(
|
import(
|
||||||
"./device-detail/integration-elements/mqtt/ha-device-actions-mqtt"
|
"./device-detail/integration-elements/mqtt/ha-device-actions-mqtt"
|
||||||
@ -949,7 +948,6 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
></ha-device-actions-zwave_js>
|
></ha-device-actions-zwave_js>
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
return templates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _showSettings() {
|
private async _showSettings() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user