From bdff3fd45280b68bd58a99e94b04b38ba08a90d9 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Fri, 29 Jan 2021 18:10:18 +0100 Subject: [PATCH] Z-wave migration tweaks (#8283) --- src/common/config/is_component_loaded.ts | 2 +- .../zwave/zwave-migration.ts | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/common/config/is_component_loaded.ts b/src/common/config/is_component_loaded.ts index 6275d705dc..1d212f3ff5 100644 --- a/src/common/config/is_component_loaded.ts +++ b/src/common/config/is_component_loaded.ts @@ -4,4 +4,4 @@ import { HomeAssistant } from "../../types"; export const isComponentLoaded = ( hass: HomeAssistant, component: string -): boolean => hass && hass.config.components.indexOf(component) !== -1; +): boolean => hass && hass.config.components.includes(component); 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 d7e791bb49..ce595713af 100644 --- a/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts +++ b/src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts @@ -39,6 +39,7 @@ import { computeDeviceName, subscribeDeviceRegistry, } from "../../../../../data/device_registry"; +import { isComponentLoaded } from "../../../../../common/config/is_component_loaded"; @customElement("zwave-migration") export class ZwaveMigration extends LitElement { @@ -94,8 +95,8 @@ export class ZwaveMigration extends LitElement { "ui.panel.config.zwave.migration.ozw.introduction" )} - ${!this.hass.config.components.includes("hassio") && - !this.hass.config.components.includes("mqtt") + ${!isComponentLoaded(this.hass, "hassio") && + !isComponentLoaded(this.hass, "mqtt") ? html`
@@ -182,7 +183,7 @@ export class ZwaveMigration extends LitElement {

Now it's time to set up the OZW integration.

- ${this.hass.config.components.includes("hassio") + ${isComponentLoaded(this.hass, "hassio") ? html`

The OZWDaemon runs in a Home Assistant addon @@ -378,7 +379,7 @@ export class ZwaveMigration extends LitElement { private async _setupOzw() { const ozwConfigFlow = await startOzwConfigFlow(this.hass); - if (this.hass.config.components.includes("ozw")) { + if (isComponentLoaded(this.hass, "ozw")) { this._getMigrationData(); this._step = 3; return; @@ -386,7 +387,7 @@ export class ZwaveMigration extends LitElement { showConfigFlowDialog(this, { continueFlowId: ozwConfigFlow.flow_id, dialogClosedCallback: () => { - if (this.hass.config.components.includes("ozw")) { + if (isComponentLoaded(this.hass, "ozw")) { this._getMigrationData(); this._step = 3; } @@ -397,7 +398,18 @@ export class ZwaveMigration extends LitElement { } private async _getMigrationData() { - this._migrationData = await migrateZwave(this.hass, true); + try { + this._migrationData = await migrateZwave(this.hass, true); + } catch (err) { + showAlertDialog(this, { + title: "Failed to get migration data!", + text: + err.code === "unknown_command" + ? "Restart Home Assistant and try again." + : err.message, + }); + return; + } this._migratedZwaveEntities = Object.keys( this._migrationData.migration_entity_map );