Correctly parse number state for numeric input card feature (#24453)

This commit is contained in:
Paul Bottein 2025-02-28 16:46:53 +01:00 committed by Bram Kragten
parent 7120200fd4
commit 76b03d3a40

View File

@ -83,13 +83,16 @@ class HuiNumericInputCardFeature
const stateObj = this.stateObj; const stateObj = this.stateObj;
const parsedState = Number(stateObj.state);
const value = !isNaN(parsedState) ? parsedState : undefined;
if (this._config.style === "buttons") { if (this._config.style === "buttons") {
return html` return html`
<ha-control-number-buttons <ha-control-number-buttons
value=${stateObj.state} .value=${value}
min=${stateObj.attributes.min} .min=${stateObj.attributes.min}
max=${stateObj.attributes.max} .max=${stateObj.attributes.max}
step=${stateObj.attributes.step} .step=${stateObj.attributes.step}
@value-changed=${this._setValue} @value-changed=${this._setValue}
.disabled=${isUnavailableState(stateObj.state)} .disabled=${isUnavailableState(stateObj.state)}
.unit=${stateObj.attributes.unit_of_measurement} .unit=${stateObj.attributes.unit_of_measurement}
@ -99,10 +102,10 @@ class HuiNumericInputCardFeature
} }
return html` return html`
<ha-control-slider <ha-control-slider
value=${stateObj.state} .value=${value}
min=${stateObj.attributes.min} .min=${stateObj.attributes.min}
max=${stateObj.attributes.max} .max=${stateObj.attributes.max}
step=${stateObj.attributes.step} .step=${stateObj.attributes.step}
@value-changed=${this._setValue} @value-changed=${this._setValue}
.disabled=${isUnavailableState(stateObj.state)} .disabled=${isUnavailableState(stateObj.state)}
.unit=${stateObj.attributes.unit_of_measurement} .unit=${stateObj.attributes.unit_of_measurement}