Fix target range temperature in tile feature (#17772)

This commit is contained in:
Paul Bottein 2023-09-01 15:24:36 +02:00 committed by GitHub
parent c291af5d97
commit fb69deb617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -129,6 +129,33 @@ class HuiTargetTemperatureTileFeature
}); });
} }
private _supportsTarget() {
const domain = computeStateDomain(this.stateObj!);
return (
(domain === "climate" &&
supportsFeature(
this.stateObj!,
ClimateEntityFeature.TARGET_TEMPERATURE
)) ||
(domain === "water_heater" &&
supportsFeature(
this.stateObj!,
WaterHeaterEntityFeature.TARGET_TEMPERATURE
))
);
}
private _supportsTargetRange() {
const domain = computeStateDomain(this.stateObj!);
return (
domain === "climate" &&
supportsFeature(
this.stateObj!,
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
)
);
}
protected render() { protected render() {
if ( if (
!this._config || !this._config ||
@ -147,19 +174,10 @@ class HuiTargetTemperatureTileFeature
minimumFractionDigits: digits, minimumFractionDigits: digits,
}; };
const domain = computeStateDomain(this.stateObj!);
if ( if (
(domain === "climate" && this._supportsTarget() &&
supportsFeature( this._targetTemperature.value != null &&
this.stateObj, this.stateObj.state !== UNAVAILABLE
ClimateEntityFeature.TARGET_TEMPERATURE
)) ||
(domain === "water_heater" &&
supportsFeature(
this.stateObj,
WaterHeaterEntityFeature.TARGET_TEMPERATURE
))
) { ) {
return html` return html`
<ha-control-button-group> <ha-control-button-group>
@ -181,30 +199,32 @@ class HuiTargetTemperatureTileFeature
.disabled=${this.stateObj!.state === UNAVAILABLE} .disabled=${this.stateObj!.state === UNAVAILABLE}
> >
</ha-control-number-buttons> </ha-control-number-buttons>
</ha-control-number-buttons> </ha-control-button-group>
`; `;
} }
if ( if (
domain === "climate" && this._supportsTargetRange() &&
supportsFeature( this._targetTemperature.low != null &&
this.stateObj, this._targetTemperature.high != null &&
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE this.stateObj.state !== UNAVAILABLE
)
) { ) {
return html` return html`
<ha-control-button-group> <ha-control-button-group>
<ha-control-number-buttons <ha-control-number-buttons
.formatOptions=${options} .formatOptions=${options}
.target=${"low"} .target=${"low"}
.value=${(this.stateObj as ClimateEntity).attributes.target_temp_low} .value=${this._targetTemperature.low}
.min=${this._min} .min=${this._min}
.max=${Math.min(this._max, this._targetTemperature.high ?? this._max)} .max=${Math.min(
this._max,
this._targetTemperature.high ?? this._max
)}
.step=${this._step} .step=${this._step}
@value-changed=${this._valueChanged} @value-changed=${this._valueChanged}
.label=${this.hass.formatEntityAttributeName( .label=${this.hass.formatEntityAttributeName(
this.stateObj, this.stateObj,
"temperature" "target_temp_low"
)} )}
style=${styleMap({ style=${styleMap({
"--control-number-buttons-focus-color": stateColor, "--control-number-buttons-focus-color": stateColor,
@ -215,14 +235,17 @@ class HuiTargetTemperatureTileFeature
<ha-control-number-buttons <ha-control-number-buttons
.formatOptions=${options} .formatOptions=${options}
.target=${"high"} .target=${"high"}
.value=${(this.stateObj as ClimateEntity).attributes.target_temp_high} .value=${this._targetTemperature.high}
.min=${Math.max(this._min, this._targetTemperature.low ?? this._min)} .min=${Math.max(
this._min,
this._targetTemperature.low ?? this._min
)}
.max=${this._max} .max=${this._max}
.step=${this._step} .step=${this._step}
@value-changed=${this._valueChanged} @value-changed=${this._valueChanged}
.label=${this.hass.formatEntityAttributeName( .label=${this.hass.formatEntityAttributeName(
this.stateObj, this.stateObj,
"temperature" "target_temp_high"
)} )}
style=${styleMap({ style=${styleMap({
"--control-number-buttons-focus-color": stateColor, "--control-number-buttons-focus-color": stateColor,
@ -230,11 +253,25 @@ class HuiTargetTemperatureTileFeature
.disabled=${this.stateObj!.state === UNAVAILABLE} .disabled=${this.stateObj!.state === UNAVAILABLE}
> >
</ha-control-number-buttons> </ha-control-number-buttons>
</ha-control-number-buttons> </ha-control-button-group>
`; `;
} }
return nothing; return html`
<ha-control-button-group>
<ha-control-number-buttons
.disabled=${this.stateObj!.state === UNAVAILABLE}
.label=${this.hass.formatEntityAttributeName(
this.stateObj,
"temperature"
)}
style=${styleMap({
"--control-number-buttons-focus-color": stateColor,
})}
>
</ha-control-number-buttons>
</ha-control-button-group>
`;
} }
static get styles() { static get styles() {