Z-wave migration tweaks (#8283)

This commit is contained in:
Bram Kragten 2021-01-29 18:10:18 +01:00
parent 1fc51f0087
commit bdff3fd452
2 changed files with 19 additions and 7 deletions

View File

@ -4,4 +4,4 @@ import { HomeAssistant } from "../../types";
export const isComponentLoaded = ( export const isComponentLoaded = (
hass: HomeAssistant, hass: HomeAssistant,
component: string component: string
): boolean => hass && hass.config.components.indexOf(component) !== -1; ): boolean => hass && hass.config.components.includes(component);

View File

@ -39,6 +39,7 @@ import {
computeDeviceName, computeDeviceName,
subscribeDeviceRegistry, subscribeDeviceRegistry,
} from "../../../../../data/device_registry"; } from "../../../../../data/device_registry";
import { isComponentLoaded } from "../../../../../common/config/is_component_loaded";
@customElement("zwave-migration") @customElement("zwave-migration")
export class ZwaveMigration extends LitElement { export class ZwaveMigration extends LitElement {
@ -94,8 +95,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("hassio") && ${!isComponentLoaded(this.hass, "hassio") &&
!this.hass.config.components.includes("mqtt") !isComponentLoaded(this.hass, "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">
@ -182,7 +183,7 @@ export class ZwaveMigration extends LitElement {
<p> <p>
Now it's time to set up the OZW integration. Now it's time to set up the OZW integration.
</p> </p>
${this.hass.config.components.includes("hassio") ${isComponentLoaded(this.hass, "hassio")
? html` ? html`
<p> <p>
The OZWDaemon runs in a Home Assistant addon The OZWDaemon runs in a Home Assistant addon
@ -378,7 +379,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 (this.hass.config.components.includes("ozw")) { if (isComponentLoaded(this.hass, "ozw")) {
this._getMigrationData(); this._getMigrationData();
this._step = 3; this._step = 3;
return; return;
@ -386,7 +387,7 @@ export class ZwaveMigration extends LitElement {
showConfigFlowDialog(this, { showConfigFlowDialog(this, {
continueFlowId: ozwConfigFlow.flow_id, continueFlowId: ozwConfigFlow.flow_id,
dialogClosedCallback: () => { dialogClosedCallback: () => {
if (this.hass.config.components.includes("ozw")) { if (isComponentLoaded(this.hass, "ozw")) {
this._getMigrationData(); this._getMigrationData();
this._step = 3; this._step = 3;
} }
@ -397,7 +398,18 @@ export class ZwaveMigration extends LitElement {
} }
private async _getMigrationData() { 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._migratedZwaveEntities = Object.keys(
this._migrationData.migration_entity_map this._migrationData.migration_entity_map
); );