mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-19 10:57:19 +00:00
Add computeStateName fallback to tile card and badges (#24666)
This commit is contained in:
parent
7009482057
commit
4f7d5053ec
@ -9,6 +9,7 @@ import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { hsv2rgb, rgb2hex, rgb2hsv } from "../../../common/color/convert-color";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateDomain } from "../../../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
import { stateColorCss } from "../../../common/entity/state_color";
|
||||
import "../../../components/ha-badge";
|
||||
@ -188,7 +189,7 @@ export class HuiEntityBadge extends LitElement implements LovelaceBadge {
|
||||
</state-display>
|
||||
`;
|
||||
|
||||
const name = this._config.name || stateObj.attributes.friendly_name;
|
||||
const name = this._config.name || computeStateName(stateObj);
|
||||
|
||||
const showState = this._config.show_state;
|
||||
const showName = this._config.show_name;
|
||||
|
@ -10,6 +10,7 @@ import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { hsv2rgb, rgb2hex, rgb2hsv } from "../../../common/color/convert-color";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
import { stateColorCss } from "../../../common/entity/state_color";
|
||||
import "../../../components/ha-card";
|
||||
@ -265,7 +266,7 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
|
||||
`;
|
||||
}
|
||||
|
||||
const name = this._config.name || stateObj.attributes.friendly_name;
|
||||
const name = this._config.name || computeStateName(stateObj);
|
||||
const active = stateActive(stateObj);
|
||||
const color = this._computeStateColor(stateObj, this._config.color);
|
||||
const domain = computeDomain(stateObj.entity_id);
|
||||
|
@ -6,6 +6,7 @@ import { repeat } from "lit/directives/repeat";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { preventDefault } from "../../../../common/dom/prevent_default";
|
||||
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||
import { computeStateName } from "../../../../common/entity/compute_state_name";
|
||||
import "../../../../components/entity/ha-entity-picker";
|
||||
import type { HaEntityPicker } from "../../../../components/entity/ha-entity-picker";
|
||||
import "../../../../components/ha-button";
|
||||
@ -55,7 +56,7 @@ export class HuiHeadingBadgesEditor extends LitElement {
|
||||
const entityId = "entity" in badge ? (badge.entity as string) : undefined;
|
||||
const stateObj = entityId ? this.hass.states[entityId] : undefined;
|
||||
return (
|
||||
(stateObj && stateObj.attributes.friendly_name) ||
|
||||
(stateObj && computeStateName(stateObj)) ||
|
||||
entityId ||
|
||||
type ||
|
||||
"Unknown badge"
|
||||
|
@ -7,6 +7,7 @@ import memoizeOne from "memoize-one";
|
||||
import { computeCssColor } from "../../../common/color/compute-color";
|
||||
import { hsv2rgb, rgb2hex, rgb2hsv } from "../../../common/color/convert-color";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||
import { stateActive } from "../../../common/entity/state_active";
|
||||
import { stateColorCss } from "../../../common/entity/state_color";
|
||||
import "../../../components/ha-heading-badge";
|
||||
@ -128,7 +129,7 @@ export class HuiEntityHeadingBadge
|
||||
"--icon-color": color,
|
||||
};
|
||||
|
||||
const name = config.name || stateObj.attributes.friendly_name;
|
||||
const name = config.name || computeStateName(stateObj);
|
||||
|
||||
return html`
|
||||
<ha-heading-badge
|
||||
|
@ -4,6 +4,7 @@ import { html, LitElement, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ensureArray } from "../common/array/ensure-array";
|
||||
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
||||
import { computeStateName } from "../common/entity/compute_state_name";
|
||||
import "../components/ha-relative-time";
|
||||
import { isUnavailableState } from "../data/entity";
|
||||
import { SENSOR_DEVICE_CLASS_TIMESTAMP } from "../data/sensor";
|
||||
@ -99,7 +100,7 @@ class StateDisplay extends LitElement {
|
||||
return this.hass!.formatEntityState(stateObj);
|
||||
}
|
||||
if (content === "name") {
|
||||
return html`${this.name || stateObj.attributes.friendly_name}`;
|
||||
return html`${this.name || computeStateName(stateObj)}`;
|
||||
}
|
||||
|
||||
let relativeDateTime: string | undefined;
|
||||
|
Loading…
x
Reference in New Issue
Block a user