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

Add reset all config for zwave node, Show default value per parameter #21894

Closed
Closed
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
21 changes: 21 additions & 0 deletions src/data/zwave_js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ export interface ZWaveJSRebuildRoutesStatusMessage {
rebuild_routes_status: { [key: number]: string };
}

export interface ZWaveJSResetAllConfigParamData {
type: string;
device_id: string;
}

export interface ZWaveJSResetAllConfigParamResult {
status?: string;
error?: string;
}

export interface ZWaveJSControllerStatisticsUpdatedMessage {
event: "statistics updated";
source: "controller";
Expand Down Expand Up @@ -872,3 +882,14 @@ export const setZWaveJSLogLevel = (
entry_id,
config: { level },
});

export const resetAllZwaveNodeConfigParameter = (
hass: HomeAssistant,
device_id: string
): Promise<ZWaveJSResetAllConfigParamResult> => {
const data: ZWaveJSResetAllConfigParamData = {
type: "zwave_js/reset_all_config_parameters",
device_id,
};
return hass.callWS(data);
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { classMap } from "lit/directives/class-map";
import memoizeOne from "memoize-one";
import "../../../../../components/ha-alert";
Expand All @@ -27,6 +28,10 @@ import "../../../../../components/ha-settings-row";
import "../../../../../components/ha-svg-icon";
import "../../../../../components/ha-switch";
import "../../../../../components/ha-textfield";
import "../../../../../components/ha-button";
import "../../../../../components/ha-dialog";
import "../../../../../components/ha-dialog-header";
import "../../../../../components/ha-icon-button";
import { groupBy } from "../../../../../common/util/group-by";
import {
computeDeviceName,
Expand All @@ -36,6 +41,7 @@ import {
import {
fetchZwaveNodeConfigParameters,
fetchZwaveNodeMetadata,
resetAllZwaveNodeConfigParameter,
setZwaveNodeConfigParameter,
ZWaveJSNodeConfigParam,
ZWaveJSNodeConfigParams,
Expand Down Expand Up @@ -89,6 +95,13 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {

@state() private _error?: string;

@state() private _resetDialog:
| "hidden"
| "info"
| "loading"
| "success"
| "error" = "hidden";

public connectedCallback(): void {
super.connectedCallback();
this.deviceId = this.route.path.substr(1);
Expand Down Expand Up @@ -127,6 +140,8 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {

const device = this._device!;

const deviceName = device ? computeDeviceName(device, this.hass) : "";

return html`
<hass-tabs-subpage
.hass=${this.hass}
Expand All @@ -147,7 +162,7 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
${device
? html`
<div class="device-info">
<h2>${computeDeviceName(device, this.hass)}</h2>
<h2>${deviceName}</h2>
<p>${device.manufacturer} ${device.model}</p>
</div>
`
Expand Down Expand Up @@ -207,8 +222,91 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
</ha-card>
</div>`
)}
<div class="reset">
<ha-button @click=${this._openResetDialog}>
${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.button_label"
)}
</ha-button>
</div>
</ha-config-section>
</hass-tabs-subpage>
${this._resetDialog !== "hidden"
? html`
<ha-dialog
open
@closed=${this._closeResetDialog}
heading=" "
scrimClickAction=${ifDefined(
this._resetDialog === "loading" ? "" : undefined
)}
escapeKeyAction=${ifDefined(
this._resetDialog === "loading" ? "" : undefined
)}
>
<ha-dialog-header slot="heading">
<span
slot="title"
.title=${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.title"
)}
>${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.title"
)}</span
>
</ha-dialog-header>
${this._resetDialog === "info"
? html`
${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text",
{ deviceName: html`<b>${deviceName}</b>` }
)}
`
: this._resetDialog === "loading"
? html`
${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_loading"
)}
`
: this._resetDialog === "success"
? html`
${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_success",
{ deviceName: html`<b>${deviceName}</b>` }
)}
`
: this._resetDialog === "error"
? html`
${this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_error",
{ deviceName: html`<b>${deviceName}</b>` }
)}
`
: nothing}
${this._resetDialog === "info"
? html`<mwc-button
slot="primaryAction"
@click=${this._closeResetDialog}
>
${this.hass.localize("ui.common.cancel")}
</mwc-button>`
: nothing}
<mwc-button
slot="primaryAction"
@click=${this._resetDialog === "info"
? this._resetAllConfigParameters
: this._closeResetDialog}
.disabled=${this._resetDialog === "loading"}
>
${this._resetDialog === "info"
? this.hass.localize(
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.reset"
)
: this.hass.localize("ui.common.close")}
</mwc-button>
</ha-dialog>
`
: nothing}
`;
}

Expand Down Expand Up @@ -441,6 +539,26 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
]);
}

private _openResetDialog() {
this._resetDialog = "info";
}

private _closeResetDialog() {
this._resetDialog = "hidden";
}

private async _resetAllConfigParameters() {
this._resetDialog = "loading";
try {
await resetAllZwaveNodeConfigParameter(this.hass, this._device!.id);

await this._fetchData();
this._resetDialog = "success";
} catch (err: any) {
this._resetDialog = "error";
}
}

static get styles(): CSSResultGroup {
return [
haStyle,
Expand Down Expand Up @@ -523,6 +641,12 @@ class ZWaveJSNodeConfig extends SubscribeMixin(LitElement) {
.switch {
text-align: right;
}

.reset {
display: flex;
justify-content: flex-end;
margin-bottom: 24px;
}
`,
];
}
Expand Down
14 changes: 13 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4900,7 +4900,19 @@
"set_param_queued": "The parameter change has been queued, and will be updated when the device wakes up.",
"set_param_error": "An error occurred.",
"parameter": "Parameter",
"bitmask": "Bitmask"
"bitmask": "Bitmask",
"reset_to_default": {
"button_label": "Reset to default configuration",
"dialog": {
"title": "Reset to default",
"text": "Are you sure you want to reset all configuration parameters of the device {deviceName} to their default values?",
wendevlin marked this conversation as resolved.
Show resolved Hide resolved
"text_loading": "Resetting in progress…",
"text_success": "The device configuration for {deviceName} has been reset to its default values.",
"text_error": "Something went wrong while resetting the device {deviceName} to its default values. Please check your logs!",
"reset": "Reset",
"cancel": "Cancel"
}
}
},
"network_status": {
"connected": "Connected",
Expand Down