mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 00:36:34 +00:00
Fix race condition in zwave migration (#8268)
This commit is contained in:
parent
448d19bfbb
commit
101067d018
@ -37,8 +37,7 @@ import { showAlertDialog } from "../../../../../dialogs/generic/show-dialog-box"
|
|||||||
import { computeStateName } from "../../../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../../../common/entity/compute_state_name";
|
||||||
import {
|
import {
|
||||||
computeDeviceName,
|
computeDeviceName,
|
||||||
DeviceRegistryEntry,
|
subscribeDeviceRegistry,
|
||||||
fetchDeviceRegistry,
|
|
||||||
} from "../../../../../data/device_registry";
|
} from "../../../../../data/device_registry";
|
||||||
|
|
||||||
@customElement("zwave-migration")
|
@customElement("zwave-migration")
|
||||||
@ -53,8 +52,6 @@ export class ZwaveMigration extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _networkStatus?: ZWaveNetworkStatus;
|
@internalProperty() private _networkStatus?: ZWaveNetworkStatus;
|
||||||
|
|
||||||
@internalProperty() private _unsub?: Promise<UnsubscribeFunc>;
|
|
||||||
|
|
||||||
@internalProperty() private _step = 0;
|
@internalProperty() private _step = 0;
|
||||||
|
|
||||||
@internalProperty() private _stoppingNetwork = false;
|
@internalProperty() private _stoppingNetwork = false;
|
||||||
@ -65,10 +62,18 @@ export class ZwaveMigration extends LitElement {
|
|||||||
|
|
||||||
@internalProperty() private _migratedZwaveEntities?: string[];
|
@internalProperty() private _migratedZwaveEntities?: string[];
|
||||||
|
|
||||||
@internalProperty() private _deviceRegistry?: DeviceRegistryEntry[];
|
@internalProperty() private _deviceNameLookup: { [id: string]: string } = {};
|
||||||
|
|
||||||
|
private _unsub?: Promise<UnsubscribeFunc>;
|
||||||
|
|
||||||
|
private _unsubDevices?: UnsubscribeFunc;
|
||||||
|
|
||||||
public disconnectedCallback(): void {
|
public disconnectedCallback(): void {
|
||||||
this._unsubscribe();
|
this._unsubscribe();
|
||||||
|
if (this._unsubDevices) {
|
||||||
|
this._unsubDevices();
|
||||||
|
this._unsubDevices = undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@ -89,7 +94,8 @@ export class ZwaveMigration extends LitElement {
|
|||||||
"ui.panel.config.zwave.migration.ozw.introduction"
|
"ui.panel.config.zwave.migration.ozw.introduction"
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
${!this.hass.config.components.includes("mqtt")
|
${!this.hass.config.components.includes("hassio") &&
|
||||||
|
!this.hass.config.components.includes("mqtt")
|
||||||
? html`
|
? html`
|
||||||
<ha-card class="content" header="MQTT Required">
|
<ha-card class="content" header="MQTT Required">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
@ -277,9 +283,9 @@ export class ZwaveMigration extends LitElement {
|
|||||||
).map(
|
).map(
|
||||||
(device_id) =>
|
(device_id) =>
|
||||||
html`<li>
|
html`<li>
|
||||||
${this._computeDeviceName(
|
${this._deviceNameLookup[
|
||||||
device_id
|
device_id
|
||||||
)}
|
] || device_id}
|
||||||
</li>`
|
</li>`
|
||||||
)}
|
)}
|
||||||
</ul>`
|
</ul>`
|
||||||
@ -372,10 +378,7 @@ export class ZwaveMigration extends LitElement {
|
|||||||
|
|
||||||
private async _setupOzw() {
|
private async _setupOzw() {
|
||||||
const ozwConfigFlow = await startOzwConfigFlow(this.hass);
|
const ozwConfigFlow = await startOzwConfigFlow(this.hass);
|
||||||
if (
|
if (this.hass.config.components.includes("ozw")) {
|
||||||
!this.hass.config.components.includes("hassio") &&
|
|
||||||
this.hass.config.components.includes("ozw")
|
|
||||||
) {
|
|
||||||
this._getMigrationData();
|
this._getMigrationData();
|
||||||
this._step = 3;
|
this._step = 3;
|
||||||
return;
|
return;
|
||||||
@ -399,18 +402,29 @@ export class ZwaveMigration extends LitElement {
|
|||||||
this._migrationData.migration_entity_map
|
this._migrationData.migration_entity_map
|
||||||
);
|
);
|
||||||
if (Object.keys(this._migrationData.migration_device_map).length) {
|
if (Object.keys(this._migrationData.migration_device_map).length) {
|
||||||
this._deviceRegistry = await fetchDeviceRegistry(this.hass);
|
this._fetchDevices();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _computeDeviceName(deviceId) {
|
private _fetchDevices() {
|
||||||
const device = this._deviceRegistry?.find(
|
this._unsubDevices = subscribeDeviceRegistry(
|
||||||
(devReg) => devReg.id === deviceId
|
this.hass.connection,
|
||||||
);
|
(devices) => {
|
||||||
if (!device) {
|
if (!this._migrationData) {
|
||||||
return deviceId;
|
return;
|
||||||
}
|
}
|
||||||
return computeDeviceName(device, this.hass);
|
const migrationDevices = Object.keys(
|
||||||
|
this._migrationData.migration_device_map
|
||||||
|
);
|
||||||
|
const deviceNameLookup = {};
|
||||||
|
devices.forEach((device) => {
|
||||||
|
if (migrationDevices.includes(device.id)) {
|
||||||
|
deviceNameLookup[device.id] = computeDeviceName(device, this.hass);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this._deviceNameLookup = deviceNameLookup;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _doMigrate() {
|
private async _doMigrate() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user