mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +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;
|
||||
unit: string;
|
||||
states: { [key: number]: string };
|
||||
default: any;
|
||||
}
|
||||
|
||||
export interface ZWaveJSSetConfigParamData {
|
||||
|
@ -24,8 +24,8 @@ import "../../../../../components/ha-icon-next";
|
||||
import "../../../../../components/ha-select";
|
||||
import "../../../../../components/ha-settings-row";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/ha-switch";
|
||||
import "../../../../../components/ha-textfield";
|
||||
import "../../../../../components/ha-selector/ha-selector-boolean";
|
||||
import { computeDeviceName } from "../../../../../data/device_registry";
|
||||
import {
|
||||
ZWaveJSNodeConfigParam,
|
||||
@ -189,6 +189,11 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
item: ZWaveJSNodeConfigParam
|
||||
): TemplateResult {
|
||||
const result = this._results[id];
|
||||
|
||||
const isTypeBoolean =
|
||||
item.configuration_value_type === "boolean" ||
|
||||
this._isEnumeratedBool(item);
|
||||
|
||||
const labelAndDescription = html`
|
||||
<span slot="prefix" class="prefix">
|
||||
${this.hass.localize("ui.panel.config.zwave_js.node_config.parameter")}
|
||||
@ -240,23 +245,36 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
</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
|
||||
if (
|
||||
item.configuration_value_type === "boolean" ||
|
||||
this._isEnumeratedBool(item)
|
||||
) {
|
||||
if (isTypeBoolean) {
|
||||
return html`
|
||||
${labelAndDescription}
|
||||
<div class="switch">
|
||||
<ha-switch
|
||||
<ha-selector-boolean
|
||||
.property=${item.property}
|
||||
.endpoint=${item.endpoint}
|
||||
.propertyKey=${item.property_key}
|
||||
.checked=${item.value === 1}
|
||||
.value=${item.value === 1}
|
||||
.key=${id}
|
||||
@change=${this._switchToggled}
|
||||
.disabled=${!item.metadata.writeable}
|
||||
></ha-switch>
|
||||
.helper=${defaultLabel}
|
||||
></ha-selector-boolean>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@ -275,10 +293,7 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
.disabled=${!item.metadata.writeable}
|
||||
@change=${this._numericInputChanged}
|
||||
.suffix=${item.metadata.unit}
|
||||
.helper=${this.hass.localize(
|
||||
"ui.panel.config.zwave_js.node_config.between_min_max",
|
||||
{ min: item.metadata.min, max: item.metadata.max }
|
||||
)}
|
||||
.helper=${`${this.hass.localize("ui.panel.config.zwave_js.node_config.between_min_max", { min: item.metadata.min, max: item.metadata.max })}${defaultLabel ? `, ${defaultLabel}` : ""}`}
|
||||
helperPersistent
|
||||
>
|
||||
</ha-textfield>`;
|
||||
@ -295,6 +310,7 @@ class ZWaveJSNodeConfig extends LitElement {
|
||||
.endpoint=${item.endpoint}
|
||||
.propertyKey=${item.property_key}
|
||||
@selected=${this._dropdownSelected}
|
||||
.helper=${defaultLabel}
|
||||
>
|
||||
${Object.entries(item.metadata.states).map(
|
||||
([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_error": "An error occurred.",
|
||||
"parameter": "Parameter",
|
||||
"bitmask": "Bitmask"
|
||||
"bitmask": "Bitmask",
|
||||
"default": "Default"
|
||||
},
|
||||
"network_status": {
|
||||
"connected": "Connected",
|
||||
|
Loading…
x
Reference in New Issue
Block a user