Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with state_color as false #19776

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/entity/state-badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 1 addition & 5 deletions src/panels/lovelace/cards/hui-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/panels/lovelace/cards/hui-entities-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
private renderEntity(entityConf: LovelaceRowConfig): TemplateResult {
steverep marked this conversation as resolved.
Show resolved Hide resolved
const element = createRowElement(
(!("type" in entityConf) || entityConf.type === "conditional") &&
steverep marked this conversation as resolved.
Show resolved Hide resolved
this._config!.state_color
"state_color" in this._config!
? ({
state_color: true,
state_color: this._config.state_color,
...(entityConf as EntityConfig),
} as EntityConfig)
: entityConf
Expand Down
6 changes: 1 addition & 5 deletions src/panels/lovelace/cards/hui-entity-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 8 additions & 9 deletions src/panels/lovelace/cards/hui-glance-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
state_color: true,
...config,
};
const entities = processConfigEntities<GlanceConfigEntity>(
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 (
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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}
></state-badge>
`
Expand Down
6 changes: 4 additions & 2 deletions src/panels/lovelace/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ 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,
EntityFilterEntityConfig,
LovelaceRowConfig,
} from "../entity-rows/types";
import { LovelaceHeaderFooterConfig } from "../header-footer/types";
import { LovelaceCardFeatureConfig } from "../card-features/types";

export type AlarmPanelCardConfigState =
| "arm_away"
Expand Down Expand Up @@ -245,6 +246,7 @@ export interface GlanceConfigEntity extends ConfigEntity {
image?: string;
show_state?: boolean;
state_color?: boolean;
format: TimestampRenderingFormat;
}

export interface GlanceCardConfig extends LovelaceCardConfig {
Expand All @@ -253,7 +255,7 @@ export interface GlanceCardConfig extends LovelaceCardConfig {
show_icon?: boolean;
title?: string;
theme?: string;
entities: Array<string | ConfigEntity>;
entities: (string | GlanceConfigEntity)[];
columns?: number;
state_color?: boolean;
}
Expand Down
Loading