mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Fix zwave migration (#11751)
This commit is contained in:
parent
eaf97ee7f5
commit
a5ee610af5
@ -1,4 +1,5 @@
|
|||||||
import { Connection, createCollection } from "home-assistant-js-websocket";
|
import { Connection, createCollection } from "home-assistant-js-websocket";
|
||||||
|
import { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import { debounce } from "../common/util/debounce";
|
import { debounce } from "../common/util/debounce";
|
||||||
@ -88,12 +89,15 @@ export const removeConfigEntryFromDevice = (
|
|||||||
config_entry_id: configEntryId,
|
config_entry_id: configEntryId,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const fetchDeviceRegistry = (conn) =>
|
export const fetchDeviceRegistry = (conn: Connection) =>
|
||||||
conn.sendMessagePromise({
|
conn.sendMessagePromise<DeviceRegistryEntry[]>({
|
||||||
type: "config/device_registry/list",
|
type: "config/device_registry/list",
|
||||||
});
|
});
|
||||||
|
|
||||||
const subscribeDeviceRegistryUpdates = (conn, store) =>
|
const subscribeDeviceRegistryUpdates = (
|
||||||
|
conn: Connection,
|
||||||
|
store: Store<DeviceRegistryEntry[]>
|
||||||
|
) =>
|
||||||
conn.subscribeEvents(
|
conn.subscribeEvents(
|
||||||
debounce(
|
debounce(
|
||||||
() =>
|
() =>
|
||||||
|
@ -5,9 +5,11 @@ import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
|||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { isComponentLoaded } from "../../../../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../../../../common/config/is_component_loaded";
|
||||||
|
import { computeStateDomain } from "../../../../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../../../common/entity/compute_state_name";
|
||||||
import "../../../../../components/buttons/ha-call-api-button";
|
import "../../../../../components/buttons/ha-call-api-button";
|
||||||
import "../../../../../components/buttons/ha-call-service-button";
|
import "../../../../../components/buttons/ha-call-service-button";
|
||||||
|
import "../../../../../components/ha-alert";
|
||||||
import "../../../../../components/ha-card";
|
import "../../../../../components/ha-card";
|
||||||
import "../../../../../components/ha-circular-progress";
|
import "../../../../../components/ha-circular-progress";
|
||||||
import "../../../../../components/ha-icon";
|
import "../../../../../components/ha-icon";
|
||||||
@ -18,30 +20,28 @@ import {
|
|||||||
fetchDeviceRegistry,
|
fetchDeviceRegistry,
|
||||||
subscribeDeviceRegistry,
|
subscribeDeviceRegistry,
|
||||||
} from "../../../../../data/device_registry";
|
} from "../../../../../data/device_registry";
|
||||||
import {
|
|
||||||
migrateZwave,
|
|
||||||
ZWaveJsMigrationData,
|
|
||||||
fetchZwaveNetworkStatus as fetchZwaveJsNetworkStatus,
|
|
||||||
fetchZwaveNodeStatus,
|
|
||||||
getZwaveJsIdentifiersFromDevice,
|
|
||||||
subscribeZwaveNodeReady,
|
|
||||||
} from "../../../../../data/zwave_js";
|
|
||||||
import {
|
import {
|
||||||
fetchMigrationConfig,
|
fetchMigrationConfig,
|
||||||
|
fetchNetworkStatus,
|
||||||
startZwaveJsConfigFlow,
|
startZwaveJsConfigFlow,
|
||||||
ZWaveMigrationConfig,
|
ZWaveMigrationConfig,
|
||||||
ZWaveNetworkStatus,
|
ZWaveNetworkStatus,
|
||||||
ZWAVE_NETWORK_STATE_STOPPED,
|
ZWAVE_NETWORK_STATE_STOPPED,
|
||||||
fetchNetworkStatus,
|
|
||||||
} from "../../../../../data/zwave";
|
} from "../../../../../data/zwave";
|
||||||
|
import {
|
||||||
|
fetchZwaveNetworkStatus as fetchZwaveJsNetworkStatus,
|
||||||
|
fetchZwaveNodeStatus,
|
||||||
|
getZwaveJsIdentifiersFromDevice,
|
||||||
|
migrateZwave,
|
||||||
|
subscribeZwaveNodeReady,
|
||||||
|
ZWaveJsMigrationData,
|
||||||
|
} from "../../../../../data/zwave_js";
|
||||||
import { showConfigFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-config-flow";
|
import { showConfigFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-config-flow";
|
||||||
import { showAlertDialog } from "../../../../../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../../../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../../../layouts/hass-subpage";
|
import "../../../../../layouts/hass-subpage";
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../../../types";
|
import type { HomeAssistant, Route } from "../../../../../types";
|
||||||
import "../../../ha-config-section";
|
import "../../../ha-config-section";
|
||||||
import { computeStateDomain } from "../../../../../common/entity/compute_state_domain";
|
|
||||||
import "../../../../../components/ha-alert";
|
|
||||||
|
|
||||||
@customElement("zwave-migration")
|
@customElement("zwave-migration")
|
||||||
export class ZwaveMigration extends LitElement {
|
export class ZwaveMigration extends LitElement {
|
||||||
@ -155,7 +155,7 @@ export class ZwaveMigration extends LitElement {
|
|||||||
.filter(
|
.filter(
|
||||||
(entityState) =>
|
(entityState) =>
|
||||||
computeStateDomain(entityState) === "zwave" &&
|
computeStateDomain(entityState) === "zwave" &&
|
||||||
entityState.state !== "ready"
|
!["ready", "sleeping"].includes(entityState.state)
|
||||||
)
|
)
|
||||||
.map(
|
.map(
|
||||||
(entityState) =>
|
(entityState) =>
|
||||||
@ -430,6 +430,10 @@ export class ZwaveMigration extends LitElement {
|
|||||||
const nodesNotReady = (await Promise.all(nodeStatePromisses)).filter(
|
const nodesNotReady = (await Promise.all(nodeStatePromisses)).filter(
|
||||||
(node) => !node.ready
|
(node) => !node.ready
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log("waiting for nodes to be ready", nodesNotReady);
|
||||||
|
|
||||||
this._getMigrationData();
|
this._getMigrationData();
|
||||||
if (nodesNotReady.length === 0) {
|
if (nodesNotReady.length === 0) {
|
||||||
this._waitingOnDevices = [];
|
this._waitingOnDevices = [];
|
||||||
@ -445,10 +449,19 @@ export class ZwaveMigration extends LitElement {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const deviceReg = await fetchDeviceRegistry(this.hass);
|
const deviceReg: DeviceRegistryEntry[] = await fetchDeviceRegistry(
|
||||||
this._waitingOnDevices = deviceReg
|
this.hass.connection
|
||||||
.map((device) => getZwaveJsIdentifiersFromDevice(device))
|
);
|
||||||
.filter(Boolean);
|
this._waitingOnDevices = deviceReg.filter((device) => {
|
||||||
|
const identifiers = getZwaveJsIdentifiersFromDevice(device);
|
||||||
|
if (
|
||||||
|
!identifiers ||
|
||||||
|
Number(identifiers.home_id) !== networkStatus.controller.home_id
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return nodesNotReady.some((node) => identifiers.node_id === node.node_id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getMigrationData() {
|
private async _getMigrationData() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user