mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add default value to zwave config params (#21990)
* Add default value to zwave config params * Remove unused ha-switch from zwave node config * Small fix of duplicate code in zwave node config
This commit is contained in:
parent
dc6f1efffb
commit
f260c95add
@ -252,6 +252,7 @@ export interface ZWaveJSNodeConfigParamMetadata {
|
|||||||
type: string;
|
type: string;
|
||||||
unit: string;
|
unit: string;
|
||||||
states: { [key: number]: string };
|
states: { [key: number]: string };
|
||||||
|
default: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ZWaveJSSetConfigParamData {
|
export interface ZWaveJSSetConfigParamData {
|
||||||
|
@ -24,8 +24,8 @@ import "../../../../../components/ha-icon-next";
|
|||||||
import "../../../../../components/ha-select";
|
import "../../../../../components/ha-select";
|
||||||
import "../../../../../components/ha-settings-row";
|
import "../../../../../components/ha-settings-row";
|
||||||
import "../../../../../components/ha-svg-icon";
|
import "../../../../../components/ha-svg-icon";
|
||||||
import "../../../../../components/ha-switch";
|
|
||||||
import "../../../../../components/ha-textfield";
|
import "../../../../../components/ha-textfield";
|
||||||
|
import "../../../../../components/ha-selector/ha-selector-boolean";
|
||||||
import { computeDeviceName } from "../../../../../data/device_registry";
|
import { computeDeviceName } from "../../../../../data/device_registry";
|
||||||
import {
|
import {
|
||||||
ZWaveJSNodeConfigParam,
|
ZWaveJSNodeConfigParam,
|
||||||
@ -189,6 +189,11 @@ class ZWaveJSNodeConfig extends LitElement {
|
|||||||
item: ZWaveJSNodeConfigParam
|
item: ZWaveJSNodeConfigParam
|
||||||
): TemplateResult {
|
): TemplateResult {
|
||||||
const result = this._results[id];
|
const result = this._results[id];
|
||||||
|
|
||||||
|
const isTypeBoolean =
|
||||||
|
item.configuration_value_type === "boolean" ||
|
||||||
|
this._isEnumeratedBool(item);
|
||||||
|
|
||||||
const labelAndDescription = html`
|
const labelAndDescription = html`
|
||||||
<span slot="prefix" class="prefix">
|
<span slot="prefix" class="prefix">
|
||||||
${this.hass.localize("ui.panel.config.zwave_js.node_config.parameter")}
|
${this.hass.localize("ui.panel.config.zwave_js.node_config.parameter")}
|
||||||
@ -240,23 +245,36 @@ class ZWaveJSNodeConfig extends LitElement {
|
|||||||
</span>
|
</span>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const defaultLabel =
|
||||||
|
item.metadata.writeable && item.metadata.default !== undefined
|
||||||
|
? `${this.hass.localize("ui.panel.config.zwave_js.node_config.default")}:
|
||||||
|
${
|
||||||
|
isTypeBoolean
|
||||||
|
? this.hass.localize(
|
||||||
|
item.metadata.default === 1 ? "ui.common.yes" : "ui.common.no"
|
||||||
|
)
|
||||||
|
: item.configuration_value_type === "enumerated"
|
||||||
|
? item.metadata.states[item.metadata.default] ||
|
||||||
|
item.metadata.default
|
||||||
|
: item.metadata.default
|
||||||
|
}`
|
||||||
|
: "";
|
||||||
|
|
||||||
// Numeric entries with a min value of 0 and max of 1 are considered boolean
|
// Numeric entries with a min value of 0 and max of 1 are considered boolean
|
||||||
if (
|
if (isTypeBoolean) {
|
||||||
item.configuration_value_type === "boolean" ||
|
|
||||||
this._isEnumeratedBool(item)
|
|
||||||
) {
|
|
||||||
return html`
|
return html`
|
||||||
${labelAndDescription}
|
${labelAndDescription}
|
||||||
<div class="switch">
|
<div class="switch">
|
||||||
<ha-switch
|
<ha-selector-boolean
|
||||||
.property=${item.property}
|
.property=${item.property}
|
||||||
.endpoint=${item.endpoint}
|
.endpoint=${item.endpoint}
|
||||||
.propertyKey=${item.property_key}
|
.propertyKey=${item.property_key}
|
||||||
.checked=${item.value === 1}
|
.value=${item.value === 1}
|
||||||
.key=${id}
|
.key=${id}
|
||||||
@change=${this._switchToggled}
|
@change=${this._switchToggled}
|
||||||
.disabled=${!item.metadata.writeable}
|
.disabled=${!item.metadata.writeable}
|
||||||
></ha-switch>
|
.helper=${defaultLabel}
|
||||||
|
></ha-selector-boolean>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -275,10 +293,7 @@ class ZWaveJSNodeConfig extends LitElement {
|
|||||||
.disabled=${!item.metadata.writeable}
|
.disabled=${!item.metadata.writeable}
|
||||||
@change=${this._numericInputChanged}
|
@change=${this._numericInputChanged}
|
||||||
.suffix=${item.metadata.unit}
|
.suffix=${item.metadata.unit}
|
||||||
.helper=${this.hass.localize(
|
.helper=${`${this.hass.localize("ui.panel.config.zwave_js.node_config.between_min_max", { min: item.metadata.min, max: item.metadata.max })}${defaultLabel ? `, ${defaultLabel}` : ""}`}
|
||||||
"ui.panel.config.zwave_js.node_config.between_min_max",
|
|
||||||
{ min: item.metadata.min, max: item.metadata.max }
|
|
||||||
)}
|
|
||||||
helperPersistent
|
helperPersistent
|
||||||
>
|
>
|
||||||
</ha-textfield>`;
|
</ha-textfield>`;
|
||||||
@ -295,6 +310,7 @@ class ZWaveJSNodeConfig extends LitElement {
|
|||||||
.endpoint=${item.endpoint}
|
.endpoint=${item.endpoint}
|
||||||
.propertyKey=${item.property_key}
|
.propertyKey=${item.property_key}
|
||||||
@selected=${this._dropdownSelected}
|
@selected=${this._dropdownSelected}
|
||||||
|
.helper=${defaultLabel}
|
||||||
>
|
>
|
||||||
${Object.entries(item.metadata.states).map(
|
${Object.entries(item.metadata.states).map(
|
||||||
([key, entityState]) => html`
|
([key, entityState]) => html`
|
||||||
|
@ -4903,7 +4903,8 @@
|
|||||||
"set_param_queued": "The parameter change has been queued, and will be updated when the device wakes up.",
|
"set_param_queued": "The parameter change has been queued, and will be updated when the device wakes up.",
|
||||||
"set_param_error": "An error occurred.",
|
"set_param_error": "An error occurred.",
|
||||||
"parameter": "Parameter",
|
"parameter": "Parameter",
|
||||||
"bitmask": "Bitmask"
|
"bitmask": "Bitmask",
|
||||||
|
"default": "Default"
|
||||||
},
|
},
|
||||||
"network_status": {
|
"network_status": {
|
||||||
"connected": "Connected",
|
"connected": "Connected",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user