mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix issues with state_color as false (#19776)
* Fix issues with state_color as false * Remove format from glance timestamp * Restore type assertion hack and remove conditional * Revert "removal of glance timestamp format and adjust types to make it work * Revert to minimal change just to pass false state_color
This commit is contained in:
parent
d6d61a4137
commit
45e09a262b
@ -32,7 +32,9 @@ export class StateBadge extends LitElement {
|
|||||||
|
|
||||||
@property() public overrideImage?: string;
|
@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;
|
@property() public color?: string;
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ export class StateBadge extends LitElement {
|
|||||||
const domain = this.stateObj
|
const domain = this.stateObj
|
||||||
? computeStateDomain(this.stateObj)
|
? computeStateDomain(this.stateObj)
|
||||||
: undefined;
|
: undefined;
|
||||||
return this.stateColor || (domain === "light" && this.stateColor !== false);
|
return this.stateColor ?? domain === "light";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
|
@ -134,11 +134,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
private getStateColor(stateObj: HassEntity, config: ButtonCardConfig) {
|
private getStateColor(stateObj: HassEntity, config: ButtonCardConfig) {
|
||||||
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
|
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
|
||||||
return (
|
return config && (config.state_color ?? domain === "light");
|
||||||
config &&
|
|
||||||
(config.state_color ||
|
|
||||||
(domain === "light" && config.state_color !== false))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCardSize(): number {
|
public getCardSize(): number {
|
||||||
|
@ -297,9 +297,9 @@ class HuiEntitiesCard extends LitElement implements LovelaceCard {
|
|||||||
private renderEntity(entityConf: LovelaceRowConfig): TemplateResult {
|
private renderEntity(entityConf: LovelaceRowConfig): TemplateResult {
|
||||||
const element = createRowElement(
|
const element = createRowElement(
|
||||||
(!("type" in entityConf) || entityConf.type === "conditional") &&
|
(!("type" in entityConf) || entityConf.type === "conditional") &&
|
||||||
this._config!.state_color
|
"state_color" in this._config!
|
||||||
? ({
|
? ({
|
||||||
state_color: true,
|
state_color: this._config.state_color,
|
||||||
...(entityConf as EntityConfig),
|
...(entityConf as EntityConfig),
|
||||||
} as EntityConfig)
|
} as EntityConfig)
|
||||||
: entityConf
|
: entityConf
|
||||||
|
@ -75,11 +75,7 @@ export class HuiEntityCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
private getStateColor(stateObj: HassEntity, config: EntityCardConfig) {
|
private getStateColor(stateObj: HassEntity, config: EntityCardConfig) {
|
||||||
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
|
const domain = stateObj ? computeStateDomain(stateObj) : undefined;
|
||||||
return (
|
return config && (config.state_color ?? domain === "light");
|
||||||
config &&
|
|
||||||
(config.state_color ||
|
|
||||||
(domain === "light" && config.state_color !== false))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public setConfig(config: EntityCardConfig): void {
|
public setConfig(config: EntityCardConfig): void {
|
||||||
|
@ -89,12 +89,12 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
state_color: true,
|
state_color: true,
|
||||||
...config,
|
...config,
|
||||||
};
|
};
|
||||||
const entities = processConfigEntities<GlanceConfigEntity>(
|
const entities = processConfigEntities(config.entities).map(
|
||||||
config.entities
|
(entityConf) => ({
|
||||||
).map((entityConf) => ({
|
hold_action: { action: "more-info" } as MoreInfoActionConfig,
|
||||||
hold_action: { action: "more-info" } as MoreInfoActionConfig,
|
...entityConf,
|
||||||
...entityConf,
|
})
|
||||||
}));
|
);
|
||||||
|
|
||||||
for (const entity of entities) {
|
for (const entity of entities) {
|
||||||
if (
|
if (
|
||||||
@ -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];
|
const stateObj = this.hass!.states[entityConf.entity];
|
||||||
|
|
||||||
if (!stateObj) {
|
if (!stateObj) {
|
||||||
@ -294,8 +294,7 @@ export class HuiGlanceCard extends LitElement implements LovelaceCard {
|
|||||||
.stateObj=${stateObj}
|
.stateObj=${stateObj}
|
||||||
.overrideIcon=${entityConf.icon}
|
.overrideIcon=${entityConf.icon}
|
||||||
.overrideImage=${entityConf.image}
|
.overrideImage=${entityConf.image}
|
||||||
.stateColor=${(entityConf.state_color === false ||
|
.stateColor=${entityConf.state_color ??
|
||||||
entityConf.state_color) ??
|
|
||||||
this._config!.state_color}
|
this._config!.state_color}
|
||||||
></state-badge>
|
></state-badge>
|
||||||
`
|
`
|
||||||
|
@ -4,8 +4,10 @@ import { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
|||||||
import { Statistic, StatisticType } from "../../../data/recorder";
|
import { Statistic, StatisticType } from "../../../data/recorder";
|
||||||
import { ForecastType } from "../../../data/weather";
|
import { ForecastType } from "../../../data/weather";
|
||||||
import { FullCalendarView, TranslationDict } from "../../../types";
|
import { FullCalendarView, TranslationDict } from "../../../types";
|
||||||
|
import { LovelaceCardFeatureConfig } from "../card-features/types";
|
||||||
import { Condition, LegacyCondition } from "../common/validate-condition";
|
import { Condition, LegacyCondition } from "../common/validate-condition";
|
||||||
import { HuiImage } from "../components/hui-image";
|
import { HuiImage } from "../components/hui-image";
|
||||||
|
import { TimestampRenderingFormat } from "../components/types";
|
||||||
import { LovelaceElementConfig } from "../elements/types";
|
import { LovelaceElementConfig } from "../elements/types";
|
||||||
import {
|
import {
|
||||||
EntityConfig,
|
EntityConfig,
|
||||||
@ -13,7 +15,6 @@ import {
|
|||||||
LovelaceRowConfig,
|
LovelaceRowConfig,
|
||||||
} from "../entity-rows/types";
|
} from "../entity-rows/types";
|
||||||
import { LovelaceHeaderFooterConfig } from "../header-footer/types";
|
import { LovelaceHeaderFooterConfig } from "../header-footer/types";
|
||||||
import { LovelaceCardFeatureConfig } from "../card-features/types";
|
|
||||||
|
|
||||||
export type AlarmPanelCardConfigState =
|
export type AlarmPanelCardConfigState =
|
||||||
| "arm_away"
|
| "arm_away"
|
||||||
@ -252,6 +253,7 @@ export interface GlanceConfigEntity extends ConfigEntity {
|
|||||||
image?: string;
|
image?: string;
|
||||||
show_state?: boolean;
|
show_state?: boolean;
|
||||||
state_color?: boolean;
|
state_color?: boolean;
|
||||||
|
format: TimestampRenderingFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GlanceCardConfig extends LovelaceCardConfig {
|
export interface GlanceCardConfig extends LovelaceCardConfig {
|
||||||
@ -260,7 +262,7 @@ export interface GlanceCardConfig extends LovelaceCardConfig {
|
|||||||
show_icon?: boolean;
|
show_icon?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
entities: Array<string | ConfigEntity>;
|
entities: (string | GlanceConfigEntity)[];
|
||||||
columns?: number;
|
columns?: number;
|
||||||
state_color?: boolean;
|
state_color?: boolean;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user