From ba09120ff3db274f84a98e811d3e93350ebf8ee8 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 8 Dec 2022 13:19:49 +0100 Subject: [PATCH] Add open label if cover is open on tile card (#14632) --- src/panels/lovelace/cards/hui-tile-card.ts | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/panels/lovelace/cards/hui-tile-card.ts b/src/panels/lovelace/cards/hui-tile-card.ts index 2919639891..52c8b9b96a 100644 --- a/src/panels/lovelace/cards/hui-tile-card.ts +++ b/src/panels/lovelace/cards/hui-tile-card.ts @@ -12,6 +12,7 @@ import { computeStateDisplay } from "../../../common/entity/compute_state_displa import { stateActive } from "../../../common/entity/state_active"; import { stateColorCss } from "../../../common/entity/state_color"; import { stateIconPath } from "../../../common/entity/state_icon_path"; +import { blankBeforePercent } from "../../../common/translations/blank_before_percent"; import "../../../components/ha-card"; import "../../../components/tile/ha-tile-badge"; import "../../../components/tile/ha-tile-icon"; @@ -192,30 +193,35 @@ export class HuiTileCard extends LitElement implements LovelaceCard { if (domain === "light" && stateObj.state === ON) { const brightness = (stateObj as LightEntity).attributes.brightness; if (brightness) { - return `${Math.round((brightness * 100) / 255)}%`; - } - } - - if (domain === "cover" && stateObj.state === "open") { - const position = (stateObj as CoverEntity).attributes.current_position; - if (position) { - return `${Math.round(position)}%`; + return `${Math.round((brightness * 100) / 255)}${blankBeforePercent( + this.hass!.locale + )}%`; } } if (domain === "fan" && stateObj.state === ON) { const speed = (stateObj as FanEntity).attributes.percentage; if (speed) { - return `${Math.round(speed)}%`; + return `${Math.round(speed)}${blankBeforePercent(this.hass!.locale)}%`; } } - return computeStateDisplay( + const stateDisplay = computeStateDisplay( this.hass!.localize, stateObj, this.hass!.locale, this.hass!.entities ); + + if (domain === "cover" && stateObj.state === "open") { + const position = (stateObj as CoverEntity).attributes.current_position; + if (position && position !== 100) { + return `${stateDisplay} - ${Math.round(position)}${blankBeforePercent( + this.hass!.locale + )}%`; + } + } + return stateDisplay; } protected render(): TemplateResult {