diff --git a/src/cards/thermostat-card/thermostat-card.ts b/src/cards/thermostat-card/thermostat-card.ts index 373faece2..84a67e09c 100644 --- a/src/cards/thermostat-card/thermostat-card.ts +++ b/src/cards/thermostat-card/thermostat-card.ts @@ -33,6 +33,7 @@ import { climateIconAction } from "../../utils/icons/climate-icon"; import { isActive } from "../../ha/data/entity"; import { ClimateEntity, CLIMATE_PRESET_NONE } from "../../ha/data/climate"; import { MushroomBaseElement } from "../../utils/base-element"; +import { coerceBoolean } from "../../utils/boolean"; type ThermostatCardControl = "temperature_control" | "mode_control"; @@ -143,15 +144,14 @@ export class ThermostatCard extends MushroomBaseElement implements LovelaceCard const layout = getLayoutFromConfig(this._config); const hideState = !!this._config.hide_state; - const actionIcon = climateIconAction(hvac_action); - - const icon = - this._config.icon || - (!!this._config.use_action_icon - ? hvac_action - ? actionIcon - : stateIcon(entity) - : "mdi:thermostat"); + let icon = this._config.icon || "mdi:thermostat"; + if (coerceBoolean(this._config.use_action_icon)) { + if (hvac_action && hvac_action !== "idle") { + icon = climateIconAction(hvac_action); + } else { + icon = stateIcon(entity); + } + } const step = getStepSize(this.hass, entity); diff --git a/src/utils/boolean.ts b/src/utils/boolean.ts new file mode 100644 index 000000000..02115676c --- /dev/null +++ b/src/utils/boolean.ts @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** Coerces a data-bound value (typically a string) to a boolean. */ +export function coerceBoolean(value: any): boolean { + return value != null && `${value}` !== "false"; +}