diff --git a/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts b/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts index 0dc8d750a4..d7e791bb49 100644 --- a/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts +++ b/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts @@ -37,8 +37,7 @@ import { showAlertDialog } from "../../../../../dialogs/generic/show-dialog-box" import { computeStateName } from "../../../../../common/entity/compute_state_name"; import { computeDeviceName, - DeviceRegistryEntry, - fetchDeviceRegistry, + subscribeDeviceRegistry, } from "../../../../../data/device_registry"; @customElement("zwave-migration") @@ -53,8 +52,6 @@ export class ZwaveMigration extends LitElement { @internalProperty() private _networkStatus?: ZWaveNetworkStatus; - @internalProperty() private _unsub?: Promise; - @internalProperty() private _step = 0; @internalProperty() private _stoppingNetwork = false; @@ -65,10 +62,18 @@ export class ZwaveMigration extends LitElement { @internalProperty() private _migratedZwaveEntities?: string[]; - @internalProperty() private _deviceRegistry?: DeviceRegistryEntry[]; + @internalProperty() private _deviceNameLookup: { [id: string]: string } = {}; + + private _unsub?: Promise; + + private _unsubDevices?: UnsubscribeFunc; public disconnectedCallback(): void { this._unsubscribe(); + if (this._unsubDevices) { + this._unsubDevices(); + this._unsubDevices = undefined; + } } protected render(): TemplateResult { @@ -89,7 +94,8 @@ export class ZwaveMigration extends LitElement { "ui.panel.config.zwave.migration.ozw.introduction" )} - ${!this.hass.config.components.includes("mqtt") + ${!this.hass.config.components.includes("hassio") && + !this.hass.config.components.includes("mqtt") ? html`
@@ -277,9 +283,9 @@ export class ZwaveMigration extends LitElement { ).map( (device_id) => html`
  • - ${this._computeDeviceName( + ${this._deviceNameLookup[ device_id - )} + ] || device_id}
  • ` )} ` @@ -372,10 +378,7 @@ export class ZwaveMigration extends LitElement { private async _setupOzw() { const ozwConfigFlow = await startOzwConfigFlow(this.hass); - if ( - !this.hass.config.components.includes("hassio") && - this.hass.config.components.includes("ozw") - ) { + if (this.hass.config.components.includes("ozw")) { this._getMigrationData(); this._step = 3; return; @@ -399,18 +402,29 @@ export class ZwaveMigration extends LitElement { this._migrationData.migration_entity_map ); if (Object.keys(this._migrationData.migration_device_map).length) { - this._deviceRegistry = await fetchDeviceRegistry(this.hass); + this._fetchDevices(); } } - private _computeDeviceName(deviceId) { - const device = this._deviceRegistry?.find( - (devReg) => devReg.id === deviceId + private _fetchDevices() { + this._unsubDevices = subscribeDeviceRegistry( + this.hass.connection, + (devices) => { + if (!this._migrationData) { + return; + } + 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; + } ); - if (!device) { - return deviceId; - } - return computeDeviceName(device, this.hass); } private async _doMigrate() {