Skip to content

Commit 226013d

Browse files
authored
Z-wave migration tweaks (#8283)
1 parent 8684726 commit 226013d

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/common/config/is_component_loaded.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import { HomeAssistant } from "../../types";
44
export const isComponentLoaded = (
55
hass: HomeAssistant,
66
component: string
7-
): boolean => hass && hass.config.components.indexOf(component) !== -1;
7+
): boolean => hass && hass.config.components.includes(component);

src/panels/config/integrations/integration-panels/zwave/zwave-migration.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
computeDeviceName,
4040
subscribeDeviceRegistry,
4141
} from "../../../../../data/device_registry";
42+
import { isComponentLoaded } from "../../../../../common/config/is_component_loaded";
4243

4344
@customElement("zwave-migration")
4445
export class ZwaveMigration extends LitElement {
@@ -94,8 +95,8 @@ export class ZwaveMigration extends LitElement {
9495
"ui.panel.config.zwave.migration.ozw.introduction"
9596
)}
9697
</div>
97-
${!this.hass.config.components.includes("hassio") &&
98-
!this.hass.config.components.includes("mqtt")
98+
${!isComponentLoaded(this.hass, "hassio") &&
99+
!isComponentLoaded(this.hass, "mqtt")
99100
? html`
100101
<ha-card class="content" header="MQTT Required">
101102
<div class="card-content">
@@ -182,7 +183,7 @@ export class ZwaveMigration extends LitElement {
182183
<p>
183184
Now it's time to set up the OZW integration.
184185
</p>
185-
${this.hass.config.components.includes("hassio")
186+
${isComponentLoaded(this.hass, "hassio")
186187
? html`
187188
<p>
188189
The OZWDaemon runs in a Home Assistant addon
@@ -378,15 +379,15 @@ export class ZwaveMigration extends LitElement {
378379

379380
private async _setupOzw() {
380381
const ozwConfigFlow = await startOzwConfigFlow(this.hass);
381-
if (this.hass.config.components.includes("ozw")) {
382+
if (isComponentLoaded(this.hass, "ozw")) {
382383
this._getMigrationData();
383384
this._step = 3;
384385
return;
385386
}
386387
showConfigFlowDialog(this, {
387388
continueFlowId: ozwConfigFlow.flow_id,
388389
dialogClosedCallback: () => {
389-
if (this.hass.config.components.includes("ozw")) {
390+
if (isComponentLoaded(this.hass, "ozw")) {
390391
this._getMigrationData();
391392
this._step = 3;
392393
}
@@ -397,7 +398,18 @@ export class ZwaveMigration extends LitElement {
397398
}
398399

399400
private async _getMigrationData() {
400-
this._migrationData = await migrateZwave(this.hass, true);
401+
try {
402+
this._migrationData = await migrateZwave(this.hass, true);
403+
} catch (err) {
404+
showAlertDialog(this, {
405+
title: "Failed to get migration data!",
406+
text:
407+
err.code === "unknown_command"
408+
? "Restart Home Assistant and try again."
409+
: err.message,
410+
});
411+
return;
412+
}
401413
this._migratedZwaveEntities = Object.keys(
402414
this._migrationData.migration_entity_map
403415
);

0 commit comments

Comments
 (0)