From bc218b01296b80caba12cb8393aabb79ef064abf Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Mon, 12 Feb 2024 05:35:52 +0000 Subject: [PATCH 1/5] Fix issues with state_color as false --- src/components/entity/state-badge.ts | 6 ++++-- src/panels/lovelace/cards/hui-button-card.ts | 6 +----- src/panels/lovelace/cards/hui-entities-card.ts | 11 +++++------ src/panels/lovelace/cards/hui-entity-card.ts | 6 +----- src/panels/lovelace/cards/hui-glance-card.ts | 5 ++--- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/components/entity/state-badge.ts b/src/components/entity/state-badge.ts index 75d077ed51f7..13b874a5e4c9 100644 --- a/src/components/entity/state-badge.ts +++ b/src/components/entity/state-badge.ts @@ -32,7 +32,9 @@ export class StateBadge extends LitElement { @property() public overrideImage?: string; - @property({ type: Boolean }) public stateColor = false; + // Cannot be a boolean attribute because undefined is treated different than + // false. When it is undefined, state is still colored for light entities. + @property({ attribute: false }) public stateColor?: boolean; @property() public color?: string; @@ -70,7 +72,7 @@ export class StateBadge extends LitElement { const domain = this.stateObj ? computeStateDomain(this.stateObj) : undefined; - return this.stateColor || (domain === "light" && this.stateColor !== false); + return this.stateColor ?? domain === "light"; } protected render() { diff --git a/src/panels/lovelace/cards/hui-button-card.ts b/src/panels/lovelace/cards/hui-button-card.ts index d738a1be6cf4..da2114138fae 100644 --- a/src/panels/lovelace/cards/hui-button-card.ts +++ b/src/panels/lovelace/cards/hui-button-card.ts @@ -134,11 +134,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard { private getStateColor(stateObj: HassEntity, config: ButtonCardConfig) { const domain = stateObj ? computeStateDomain(stateObj) : undefined; - return ( - config && - (config.state_color || - (domain === "light" && config.state_color !== false)) - ); + return config && (config.state_color ?? domain === "light"); } public getCardSize(): number { diff --git a/src/panels/lovelace/cards/hui-entities-card.ts b/src/panels/lovelace/cards/hui-entities-card.ts index 3d5b46449eb2..e9bd997bc7d4 100644 --- a/src/panels/lovelace/cards/hui-entities-card.ts +++ b/src/panels/lovelace/cards/hui-entities-card.ts @@ -296,12 +296,11 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { private renderEntity(entityConf: LovelaceRowConfig): TemplateResult { const element = createRowElement( - (!("type" in entityConf) || entityConf.type === "conditional") && - this._config!.state_color - ? ({ - state_color: true, - ...(entityConf as EntityConfig), - } as EntityConfig) + !("type" in entityConf) || entityConf.type === "conditional" + ? { + state_color: this._config!.state_color, + ...entityConf, + } : entityConf ); if (this._hass) { diff --git a/src/panels/lovelace/cards/hui-entity-card.ts b/src/panels/lovelace/cards/hui-entity-card.ts index fd1b63e13e3e..e6366cd28b6c 100644 --- a/src/panels/lovelace/cards/hui-entity-card.ts +++ b/src/panels/lovelace/cards/hui-entity-card.ts @@ -75,11 +75,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard { private getStateColor(stateObj: HassEntity, config: EntityCardConfig) { const domain = stateObj ? computeStateDomain(stateObj) : undefined; - return ( - config && - (config.state_color || - (domain === "light" && config.state_color !== false)) - ); + return config && (config.state_color ?? domain === "light"); } public setConfig(config: EntityCardConfig): void { diff --git a/src/panels/lovelace/cards/hui-glance-card.ts b/src/panels/lovelace/cards/hui-glance-card.ts index d48fb68cfe57..18e423a243f7 100644 --- a/src/panels/lovelace/cards/hui-glance-card.ts +++ b/src/panels/lovelace/cards/hui-glance-card.ts @@ -237,7 +237,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { `; } - private renderEntity(entityConf): TemplateResult { + private renderEntity(entityConf: GlanceConfigEntity): TemplateResult { const stateObj = this.hass!.states[entityConf.entity]; if (!stateObj) { @@ -294,8 +294,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { .stateObj=${stateObj} .overrideIcon=${entityConf.icon} .overrideImage=${entityConf.image} - .stateColor=${(entityConf.state_color === false || - entityConf.state_color) ?? + .stateColor=${entityConf.state_color ?? this._config!.state_color} > ` From a9e7fdb69a390d9deaa8e065912158bb243548bb Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Mon, 12 Feb 2024 13:56:36 +0000 Subject: [PATCH 2/5] Remove format from glance timestamp --- src/panels/lovelace/cards/hui-glance-card.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/panels/lovelace/cards/hui-glance-card.ts b/src/panels/lovelace/cards/hui-glance-card.ts index 18e423a243f7..6113868d7a9f 100644 --- a/src/panels/lovelace/cards/hui-glance-card.ts +++ b/src/panels/lovelace/cards/hui-glance-card.ts @@ -310,7 +310,6 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { ` From 4fb5fc17ac5981cfd0068a53d6b7b2bd761b41c0 Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Mon, 12 Feb 2024 19:29:47 +0000 Subject: [PATCH 3/5] Restore type assertion hack and remove conditional --- src/panels/lovelace/cards/hui-entities-card.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entities-card.ts b/src/panels/lovelace/cards/hui-entities-card.ts index e9bd997bc7d4..32ad28f9b5a1 100644 --- a/src/panels/lovelace/cards/hui-entities-card.ts +++ b/src/panels/lovelace/cards/hui-entities-card.ts @@ -295,14 +295,10 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { } private renderEntity(entityConf: LovelaceRowConfig): TemplateResult { - const element = createRowElement( - !("type" in entityConf) || entityConf.type === "conditional" - ? { - state_color: this._config!.state_color, - ...entityConf, - } - : entityConf - ); + const element = createRowElement({ + state_color: this._config!.state_color, + ...(entityConf as EntityConfig), + } as EntityConfig); if (this._hass) { element.hass = this._hass; } From e8245cb3d4ce72de2805393fea46bbbfe06e9f81 Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Tue, 13 Feb 2024 04:27:14 +0000 Subject: [PATCH 4/5] Revert "removal of glance timestamp format and adjust types to make it work --- src/panels/lovelace/cards/hui-glance-card.ts | 13 +++++++------ src/panels/lovelace/cards/types.ts | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/panels/lovelace/cards/hui-glance-card.ts b/src/panels/lovelace/cards/hui-glance-card.ts index 6113868d7a9f..8217da750166 100644 --- a/src/panels/lovelace/cards/hui-glance-card.ts +++ b/src/panels/lovelace/cards/hui-glance-card.ts @@ -89,12 +89,12 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { state_color: true, ...config, }; - const entities = processConfigEntities( - config.entities - ).map((entityConf) => ({ - hold_action: { action: "more-info" } as MoreInfoActionConfig, - ...entityConf, - })); + const entities = processConfigEntities(config.entities).map( + (entityConf) => ({ + hold_action: { action: "more-info" } as MoreInfoActionConfig, + ...entityConf, + }) + ); for (const entity of entities) { if ( @@ -310,6 +310,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard { ` diff --git a/src/panels/lovelace/cards/types.ts b/src/panels/lovelace/cards/types.ts index d9a26be158b7..b8b2947364d0 100644 --- a/src/panels/lovelace/cards/types.ts +++ b/src/panels/lovelace/cards/types.ts @@ -4,8 +4,10 @@ import { LovelaceCardConfig } from "../../../data/lovelace/config/card"; import { Statistic, StatisticType } from "../../../data/recorder"; import { ForecastType } from "../../../data/weather"; import { FullCalendarView, TranslationDict } from "../../../types"; +import { LovelaceCardFeatureConfig } from "../card-features/types"; import { Condition, LegacyCondition } from "../common/validate-condition"; import { HuiImage } from "../components/hui-image"; +import { TimestampRenderingFormat } from "../components/types"; import { LovelaceElementConfig } from "../elements/types"; import { EntityConfig, @@ -13,7 +15,6 @@ import { LovelaceRowConfig, } from "../entity-rows/types"; import { LovelaceHeaderFooterConfig } from "../header-footer/types"; -import { LovelaceCardFeatureConfig } from "../card-features/types"; export type AlarmPanelCardConfigState = | "arm_away" @@ -245,6 +246,7 @@ export interface GlanceConfigEntity extends ConfigEntity { image?: string; show_state?: boolean; state_color?: boolean; + format: TimestampRenderingFormat; } export interface GlanceCardConfig extends LovelaceCardConfig { @@ -253,7 +255,7 @@ export interface GlanceCardConfig extends LovelaceCardConfig { show_icon?: boolean; title?: string; theme?: string; - entities: Array; + entities: (string | GlanceConfigEntity)[]; columns?: number; state_color?: boolean; } From 7e7e86ac871ecccde03315d86ede9b702baac7e9 Mon Sep 17 00:00:00 2001 From: Steve Repsher Date: Wed, 14 Feb 2024 19:56:44 +0000 Subject: [PATCH 5/5] Revert to minimal change just to pass false state_color --- src/panels/lovelace/cards/hui-entities-card.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/cards/hui-entities-card.ts b/src/panels/lovelace/cards/hui-entities-card.ts index 32ad28f9b5a1..4fb12c466175 100644 --- a/src/panels/lovelace/cards/hui-entities-card.ts +++ b/src/panels/lovelace/cards/hui-entities-card.ts @@ -295,10 +295,15 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard { } private renderEntity(entityConf: LovelaceRowConfig): TemplateResult { - const element = createRowElement({ - state_color: this._config!.state_color, - ...(entityConf as EntityConfig), - } as EntityConfig); + const element = createRowElement( + (!("type" in entityConf) || entityConf.type === "conditional") && + "state_color" in this._config! + ? ({ + state_color: this._config.state_color, + ...(entityConf as EntityConfig), + } as EntityConfig) + : entityConf + ); if (this._hass) { element.hass = this._hass; }