Add unavailable badge for tile card (#14582)

add unavailable badge for tile card
This commit is contained in:
Paul Bottein 2022-12-06 18:14:18 +01:00 committed by GitHub
parent 228fd4b7fe
commit d622d9d420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import { mdiExclamationThick } from "@mdi/js";
import { HassEntity } from "home-assistant-js-websocket"; import { HassEntity } from "home-assistant-js-websocket";
import { computeDomain } from "../../../../../common/entity/compute_domain"; import { computeDomain } from "../../../../../common/entity/compute_domain";
import { UNAVAILABLE_STATES } from "../../../../../data/entity"; import { UNAVAILABLE, UNKNOWN } from "../../../../../data/entity";
import { HomeAssistant } from "../../../../../types"; import { HomeAssistant } from "../../../../../types";
import { computeClimateBadge } from "./tile-badge-climate"; import { computeClimateBadge } from "./tile-badge-climate";
import { computePersonBadge } from "./tile-badge-person"; import { computePersonBadge } from "./tile-badge-person";
@ -17,9 +18,15 @@ export type ComputeBadgeFunction = (
) => TileBadge | undefined; ) => TileBadge | undefined;
export const computeTileBadge: ComputeBadgeFunction = (stateObj, hass) => { export const computeTileBadge: ComputeBadgeFunction = (stateObj, hass) => {
if (UNAVAILABLE_STATES.includes(stateObj.state)) { if (stateObj.state === UNKNOWN) {
return undefined; return undefined;
} }
if (stateObj.state === UNAVAILABLE) {
return {
color: "var(--rgb-orange-color)",
iconPath: mdiExclamationThick,
};
}
const domain = computeDomain(stateObj.entity_id); const domain = computeDomain(stateObj.entity_id);
switch (domain) { switch (domain) {
case "person": case "person":