mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Add reset to default to zwave node config (#21991)
* Add reset to default to zwave node config * use invoke_cc_api instead of a new API --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
parent
cbfcad71d5
commit
d8df380edc
@ -13,12 +13,13 @@ import { classMap } from "lit/directives/class-map";
|
||||
import { groupBy } from "../../../../../common/util/group-by";
|
||||
import "../../../../../components/ha-alert";
|
||||
import "../../../../../components/ha-card";
|
||||
import "../../../../../components/ha-icon-next";
|
||||
import "../../../../../components/ha-select";
|
||||
import "../../../../../components/ha-settings-row";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/ha-textfield";
|
||||
import "../../../../../components/ha-selector/ha-selector-boolean";
|
||||
import "../../../../../components/buttons/ha-progress-button";
|
||||
import type { HaProgressButton } from "../../../../../components/buttons/ha-progress-button";
|
||||
import { computeDeviceName } from "../../../../../data/device_registry";
|
||||
import type {
|
||||
ZWaveJSNodeConfigParam,
|
||||
@ -29,6 +30,7 @@ import type {
|
||||
import {
|
||||
fetchZwaveNodeConfigParameters,
|
||||
fetchZwaveNodeMetadata,
|
||||
invokeZWaveCCApi,
|
||||
setZwaveNodeConfigParameter,
|
||||
} from "../../../../../data/zwave_js";
|
||||
import "../../../../../layouts/hass-error-screen";
|
||||
@ -38,6 +40,8 @@ import { haStyle } from "../../../../../resources/styles";
|
||||
import type { HomeAssistant, Route } from "../../../../../types";
|
||||
import "../../../ha-config-section";
|
||||
import { configTabs } from "./zwave_js-config-router";
|
||||
import { showConfirmationDialog } from "../../../../../dialogs/generic/show-dialog-box";
|
||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||
|
||||
const icons = {
|
||||
accepted: mdiCheckCircle,
|
||||
@ -67,6 +71,8 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
|
||||
@state() private _error?: string;
|
||||
|
||||
@state() private _resetDialogProgress = false;
|
||||
|
||||
public connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
this.deviceId = this.route.path.substr(1);
|
||||
@ -94,6 +100,8 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
|
||||
const device = this.hass.devices[this.deviceId];
|
||||
|
||||
const deviceName = device ? computeDeviceName(device, this.hass) : "";
|
||||
|
||||
return html`
|
||||
<hass-tabs-subpage
|
||||
.hass=${this.hass}
|
||||
@ -114,7 +122,7 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
${device
|
||||
? html`
|
||||
<div class="device-info">
|
||||
<h2>${computeDeviceName(device, this.hass)}</h2>
|
||||
<h2>${deviceName}</h2>
|
||||
<p>${device.manufacturer} ${device.model}</p>
|
||||
</div>
|
||||
`
|
||||
@ -174,6 +182,17 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
</ha-card>
|
||||
</div>`
|
||||
)}
|
||||
<div class="reset">
|
||||
<ha-progress-button
|
||||
.disabled=${this._resetDialogProgress}
|
||||
.progress=${this._resetDialogProgress}
|
||||
@click=${this._openResetDialog}
|
||||
>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.button_label"
|
||||
)}
|
||||
</ha-progress-button>
|
||||
</div>
|
||||
</ha-config-section>
|
||||
</hass-tabs-subpage>
|
||||
`;
|
||||
@ -438,6 +457,66 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
]);
|
||||
}
|
||||
|
||||
private async _openResetDialog(event: Event) {
|
||||
const progressButton = event.currentTarget as HaProgressButton;
|
||||
|
||||
await showConfirmationDialog(this, {
|
||||
destructive: true,
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.title"
|
||||
),
|
||||
text: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text"
|
||||
),
|
||||
confirmText: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.reset"
|
||||
),
|
||||
confirm: () => this._resetAllConfigParameters(progressButton),
|
||||
});
|
||||
}
|
||||
|
||||
private async _resetAllConfigParameters(progressButton: HaProgressButton) {
|
||||
this._resetDialogProgress = true;
|
||||
fireEvent(this, "hass-notification", {
|
||||
message: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_loading"
|
||||
),
|
||||
});
|
||||
|
||||
try {
|
||||
const device = this.hass.devices[this.deviceId];
|
||||
if (!device) {
|
||||
throw new Error("device_not_found");
|
||||
}
|
||||
await invokeZWaveCCApi(
|
||||
this.hass,
|
||||
device.id,
|
||||
0x70, // 0x70 is the command class for Configuration
|
||||
undefined,
|
||||
"resetAll",
|
||||
[],
|
||||
true
|
||||
);
|
||||
|
||||
fireEvent(this, "hass-notification", {
|
||||
message: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_success"
|
||||
),
|
||||
});
|
||||
|
||||
await this._fetchData();
|
||||
progressButton.actionSuccess();
|
||||
} catch (err: any) {
|
||||
fireEvent(this, "hass-notification", {
|
||||
message: this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.reset_to_default.dialog.text_error"
|
||||
),
|
||||
});
|
||||
progressButton.actionError();
|
||||
}
|
||||
this._resetDialogProgress = false;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
@ -520,6 +599,12 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
.switch {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.reset {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
@ -4965,6 +4965,18 @@
|
||||
"set_param_error": "An error occurred.",
|
||||
"parameter": "Parameter",
|
||||
"bitmask": "Bitmask",
|
||||
"reset_to_default": {
|
||||
"button_label": "Reset to default configuration",
|
||||
"dialog": {
|
||||
"title": "Reset to default",
|
||||
"text": "All device parameters will be reset to their default values.",
|
||||
"text_loading": "Resetting in progress…",
|
||||
"text_success": "The device configuration has been reset to its default values.",
|
||||
"text_error": "Something went wrong while resetting the device to its default values. Please check your logs!",
|
||||
"reset": "Reset",
|
||||
"cancel": "Cancel"
|
||||
}
|
||||
},
|
||||
"default": "Default"
|
||||
},
|
||||
"network_status": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user