Skip to content

Commit

Permalink
fix frontend based on backend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 committed Oct 19, 2023
1 parent c4d052b commit c2a10fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,18 @@ export const fetchZwaveNodeFirmwareUpdateCapabilities = (
device_id,
});

export const hardResetController = (
export const subscribeHardResetControllerDeviceAdded = (
hass: HomeAssistant,
entry_id: string
): Promise<string> =>
hass.callWS({
type: "zwave_js/hard_reset_controller",
entry_id,
});
entry_id: string,
callbackFunction: (message: { device_id: string }) => void
): Promise<UnsubscribeFunc> =>
hass.connection.subscribeMessage(
(message: any) => callbackFunction(message),
{
type: "zwave_js/hard_reset_controller",
entry_id: entry_id,
}
);

export const uploadFirmwareAndBeginUpdate = async (
hass: HomeAssistant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { mdiCheckCircle, mdiDeleteForever, mdiRestore } from "@mdi/js";
import "@material/mwc-button/mwc-button";
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { fireEvent } from "../../../../../common/dom/fire_event";
import { createCloseHeading } from "../../../../../components/ha-dialog";
import "../../../../../components/ha-svg-icon";
import { hardResetController } from "../../../../../data/zwave_js";
import { subscribeHardResetControllerDeviceAdded } from "../../../../../data/zwave_js";
import { haStyleDialog } from "../../../../../resources/styles";
import { HomeAssistant } from "../../../../../types";
import { ZWaveJSHardResetControllerDialogParams } from "./show-dialog-zwave_js-hard-reset-controller";
Expand All @@ -32,13 +33,16 @@ class DialogZWaveJSHardResetController extends LitElement {

@state() private _resetStatus = ResetStatus.NotStarted;

private _subscribedDeviceAdded?: Promise<UnsubscribeFunc>;

public showDialog(params: ZWaveJSHardResetControllerDialogParams): void {
this._entryId = params.entryId;
}

public closeDialog(): void {
this._entryId = undefined;
this._resetStatus = ResetStatus.NotStarted;
this._unsubscribeDeviceAdded();

fireEvent(this, "dialog-closed", { dialog: this.localName });
}
Expand Down Expand Up @@ -99,13 +103,30 @@ class DialogZWaveJSHardResetController extends LitElement {
confirmText: this.hass.localize("ui.common.continue"),
})
) {
this._subscribedDeviceAdded = subscribeHardResetControllerDeviceAdded(
this.hass,
this._entryId!,
(message: { device_id: string }) => {
setTimeout(
() => navigate(`/config/devices/device/${message.device_id}`),
0
);
this._resetStatus = ResetStatus.Done;
this._unsubscribeDeviceAdded();
}
);
this._resetStatus = ResetStatus.InProgress;
const deviceId = await hardResetController(this.hass, this._entryId!);
setTimeout(() => navigate(`/config/devices/device/${deviceId}`), 0);
this._resetStatus = ResetStatus.Done;
}
}

private _unsubscribeDeviceAdded(): void {
if (!this._subscribedDeviceAdded) {
return;
}
this._subscribedDeviceAdded.then((unsub) => unsub());
this._subscribedDeviceAdded = undefined;
}

static get styles(): CSSResultGroup {
return [
haStyleDialog,
Expand Down

0 comments on commit c2a10fc

Please sign in to comment.