Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle breaking changes as result of zwave_js lib upgrade #18009

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export interface ZWaveJSController {
supported_function_types: number[];
suc_node_id: number;
supports_timers: boolean;
is_heal_network_active: boolean;
is_rebuilding_routes: boolean;
inclusion_state: InclusionState;
nodes: ZWaveJSNodeStatus[];
}
Expand Down Expand Up @@ -278,9 +278,9 @@ export interface ZWaveJSRefreshNodeStatusMessage {
stage?: string;
}

export interface ZWaveJSHealNetworkStatusMessage {
export interface ZWaveJSRebuildRoutesStatusMessage {
event: string;
heal_node_status: { [key: number]: string };
rebuild_routes_status: { [key: number]: string };
}

export interface ZWaveJSControllerStatisticsUpdatedMessage {
Expand Down Expand Up @@ -651,12 +651,12 @@ export const reinterviewZwaveNode = (
}
);

export const healZwaveNode = (
export const rebuildZwaveNodeRoutes = (
hass: HomeAssistant,
device_id: string
): Promise<boolean> =>
hass.callWS({
type: "zwave_js/heal_node",
type: "zwave_js/rebuild_node_routes",
device_id,
});

Expand All @@ -673,33 +673,33 @@ export const removeFailedZwaveNode = (
}
);

export const healZwaveNetwork = (
export const rebuildZwaveNetworkRoutes = (
hass: HomeAssistant,
entry_id: string
): Promise<UnsubscribeFunc> =>
hass.callWS({
type: "zwave_js/begin_healing_network",
type: "zwave_js/begin_rebuilding_routes",
entry_id,
});

export const stopHealZwaveNetwork = (
export const stopRebuildingZwaveNetworkRoutes = (
hass: HomeAssistant,
entry_id: string
): Promise<UnsubscribeFunc> =>
hass.callWS({
type: "zwave_js/stop_healing_network",
type: "zwave_js/stop_rebuilding_routes",
entry_id,
});

export const subscribeHealZwaveNetworkProgress = (
export const subscribeRebuildZwaveNetworkRoutesProgress = (
hass: HomeAssistant,
entry_id: string,
callbackFunction: (message: ZWaveJSHealNetworkStatusMessage) => void
callbackFunction: (message: ZWaveJSRebuildRoutesStatusMessage) => void
): Promise<UnsubscribeFunc> =>
hass.connection.subscribeMessage(
(message: any) => callbackFunction(message),
{
type: "zwave_js/subscribe_heal_network_progress",
type: "zwave_js/subscribe_rebuild_routes_progress",
entry_id,
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "../../../../../../data/zwave_js";
import { showConfirmationDialog } from "../../../../../../dialogs/generic/show-dialog-box";
import type { HomeAssistant } from "../../../../../../types";
import { showZWaveJSHealNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-heal-node";
import { showZWaveJSRebuildNodeRoutesDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-rebuild-node-routes";
import { showZWaveJSNodeStatisticsDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-node-statistics";
import { showZWaveJSReinterviewNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-reinterview-node";
import { showZWaveJSRemoveFailedNodeDialog } from "../../../../integrations/integration-panels/zwave_js/show-dialog-zwave_js-remove-failed-node";
Expand Down Expand Up @@ -69,10 +69,12 @@ export const getZwaveDeviceActions = async (
}),
},
{
label: hass.localize("ui.panel.config.zwave_js.device_info.heal_node"),
label: hass.localize(
"ui.panel.config.zwave_js.device_info.rebuild_routes"
),
icon: mdiHospitalBox,
action: () =>
showZWaveJSHealNodeDialog(el, {
showZWaveJSRebuildNodeRoutesDialog(el, {
device,
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import { fireEvent } from "../../../../../common/dom/fire_event";
import { createCloseHeading } from "../../../../../components/ha-dialog";
import {
fetchZwaveNetworkStatus,
healZwaveNetwork,
stopHealZwaveNetwork,
subscribeHealZwaveNetworkProgress,
ZWaveJSHealNetworkStatusMessage,
rebuildZwaveNetworkRoutes,
stopRebuildingZwaveNetworkRoutes,
subscribeRebuildZwaveNetworkRoutesProgress,
ZWaveJSRebuildRoutesStatusMessage,
ZWaveJSNetwork,
} from "../../../../../data/zwave_js";
import { haStyleDialog } from "../../../../../resources/styles";
import { HomeAssistant } from "../../../../../types";
import { ZWaveJSHealNetworkDialogParams } from "./show-dialog-zwave_js-heal-network";
import { ZWaveJSRebuildNetworkRoutesDialogParams } from "./show-dialog-zwave_js-rebuild-network-routes";

@customElement("dialog-zwave_js-heal-network")
class DialogZWaveJSHealNetwork extends LitElement {
@customElement("dialog-zwave_js-rebuild-network-routes")
class DialogZWaveJSRebuildNetworkRoutes extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@state() private entry_id?: string;
Expand All @@ -34,7 +34,7 @@ class DialogZWaveJSHealNetwork extends LitElement {

private _subscribed?: Promise<UnsubscribeFunc>;

public showDialog(params: ZWaveJSHealNetworkDialogParams): void {
public showDialog(params: ZWaveJSRebuildNetworkRoutesDialogParams): void {
this._progress_total = 0;
this.entry_id = params.entry_id;
this._fetchData();
Expand All @@ -61,7 +61,9 @@ class DialogZWaveJSHealNetwork extends LitElement {
@closed=${this.closeDialog}
.heading=${createCloseHeading(
this.hass,
this.hass.localize("ui.panel.config.zwave_js.heal_network.title")
this.hass.localize(
"ui.panel.config.zwave_js.rebuild_network_routes.title"
)
)}
>
${!this._status
Expand All @@ -74,21 +76,24 @@ class DialogZWaveJSHealNetwork extends LitElement {
<div class="status">
<p>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.introduction"
"ui.panel.config.zwave_js.rebuild_network_routes.introduction"
)}
</p>
</div>
</div>
<p>
<em>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.traffic_warning"
"ui.panel.config.zwave_js.rebuild_network_routes.traffic_warning"
)}
</em>
</p>
<mwc-button slot="primaryAction" @click=${this._startHeal}>
<mwc-button
slot="primaryAction"
@click=${this._startRebuildingRoutes}
>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.start_heal"
"ui.panel.config.zwave_js.rebuild_network_routes.start_rebuilding_routes"
)}
</mwc-button>
`
Expand All @@ -99,13 +104,13 @@ class DialogZWaveJSHealNetwork extends LitElement {
<p>
<b>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.in_progress"
"ui.panel.config.zwave_js.rebuild_network_routes.in_progress"
)}
</b>
</p>
<p>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.run_in_background"
"ui.panel.config.zwave_js.rebuild_network_routes.run_in_background"
)}
</p>
</div>
Expand All @@ -114,9 +119,12 @@ class DialogZWaveJSHealNetwork extends LitElement {
<mwc-linear-progress indeterminate> </mwc-linear-progress>
`
: ""}
<mwc-button slot="secondaryAction" @click=${this._stopHeal}>
<mwc-button
slot="secondaryAction"
@click=${this._stopRebuildingRoutes}
>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.stop_heal"
"ui.panel.config.zwave_js.rebuild_network_routes.stop_rebuilding_routes"
)}
</mwc-button>
<mwc-button slot="primaryAction" @click=${this.closeDialog}>
Expand All @@ -134,7 +142,7 @@ class DialogZWaveJSHealNetwork extends LitElement {
<div class="status">
<p>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.healing_failed"
"ui.panel.config.zwave_js.rebuild_network_routes.rebuilding_routes_failed"
)}
</p>
</div>
Expand All @@ -154,7 +162,7 @@ class DialogZWaveJSHealNetwork extends LitElement {
<div class="status">
<p>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.healing_complete"
"ui.panel.config.zwave_js.rebuild_network_routes.rebuilding_routes_complete"
)}
</p>
</div>
Expand All @@ -174,7 +182,7 @@ class DialogZWaveJSHealNetwork extends LitElement {
<div class="status">
<p>
${this.hass.localize(
"ui.panel.config.zwave_js.heal_network.healing_cancelled"
"ui.panel.config.zwave_js.rebuild_network_routes.rebuilding_routes_cancelled"
)}
</p>
</div>
Expand Down Expand Up @@ -205,55 +213,55 @@ class DialogZWaveJSHealNetwork extends LitElement {
const network: ZWaveJSNetwork = await fetchZwaveNetworkStatus(this.hass!, {
entry_id: this.entry_id!,
});
if (network.controller.is_heal_network_active) {
if (network.controller.is_rebuilding_routes) {
this._status = "started";
this._subscribed = subscribeHealZwaveNetworkProgress(
this._subscribed = subscribeRebuildZwaveNetworkRoutesProgress(
this.hass,
this.entry_id!,
this._handleMessage.bind(this)
);
}
}

private _startHeal(): void {
private _startRebuildingRoutes(): void {
if (!this.hass) {
return;
}
healZwaveNetwork(this.hass, this.entry_id!);
rebuildZwaveNetworkRoutes(this.hass, this.entry_id!);
this._status = "started";
this._subscribed = subscribeHealZwaveNetworkProgress(
this._subscribed = subscribeRebuildZwaveNetworkRoutesProgress(
this.hass,
this.entry_id!,
this._handleMessage.bind(this)
);
}

private _stopHeal(): void {
private _stopRebuildingRoutes(): void {
if (!this.hass) {
return;
}
stopHealZwaveNetwork(this.hass, this.entry_id!);
stopRebuildingZwaveNetworkRoutes(this.hass, this.entry_id!);
this._unsubscribe();
this._status = "cancelled";
}

private _handleMessage(message: ZWaveJSHealNetworkStatusMessage): void {
if (message.event === "heal network progress") {
private _handleMessage(message: ZWaveJSRebuildRoutesStatusMessage): void {
if (message.event === "rebuild routes progress") {
let finished = 0;
let in_progress = 0;
for (const status of Object.values(message.heal_node_status)) {
for (const status of Object.values(message.rebuild_routes_status)) {
if (status === "pending") {
in_progress++;
}
if (["skipped", "failed", "done"].includes(status)) {
finished++;
}
}
this._progress_total = Object.keys(message.heal_node_status).length;
this._progress_total = Object.keys(message.rebuild_routes_status).length;
this._progress_finished = finished / this._progress_total;
this._progress_in_progress = in_progress / this._progress_total;
}
if (message.event === "heal network done") {
if (message.event === "rebuild routes done") {
this._unsubscribe();
this._status = "finished";
}
Expand Down Expand Up @@ -306,6 +314,6 @@ class DialogZWaveJSHealNetwork extends LitElement {

declare global {
interface HTMLElementTagNameMap {
"dialog-zwave_js-heal-network": DialogZWaveJSHealNetwork;
"dialog-zwave_js-rebuild-network-routes": DialogZWaveJSRebuildNetworkRoutes;
}
}
Loading
Loading