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