Skip to content

Commit

Permalink
feat: improve state/action icon usage (piitaya#21)
Browse files Browse the repository at this point in the history
Closes piitaya#16
  • Loading branch information
ulic75 committed May 31, 2022
1 parent d11b1e7 commit f988372
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/cards/thermostat-card/thermostat-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions src/utils/boolean.ts
Original file line number Diff line number Diff line change
@@ -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";
}

0 comments on commit f988372

Please sign in to comment.