Leave climate humidity mode if entity stops supporting it (#21423)

* Leave climate humidity mode if entity stops supporting it

* check changedProps
This commit is contained in:
karwosts 2024-07-22 01:28:51 -07:00 committed by GitHub
parent f05ddd3fcd
commit bbb64870a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,14 @@ import {
mdiTuneVariant,
mdiWaterPercent,
} from "@mdi/js";
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
import {
CSSResultGroup,
LitElement,
PropertyValues,
css,
html,
nothing,
} from "lit";
import { property, state } from "lit/decorators";
import { stopPropagation } from "../../../common/dom/stop_propagation";
import { supportsFeature } from "../../../common/entity/supports-feature";
@ -39,6 +46,17 @@ class MoreInfoClimate extends LitElement {
@state() private _mainControl: MainControl = "temperature";
protected willUpdate(changedProps: PropertyValues): void {
if (
changedProps.has("stateObj") &&
this.stateObj &&
this._mainControl === "humidity" &&
!supportsFeature(this.stateObj, ClimateEntityFeature.TARGET_HUMIDITY)
) {
this._mainControl = "temperature";
}
}
protected render() {
if (!this.stateObj) {
return nothing;