mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Handle non existing states (#2098)
This commit is contained in:
parent
a7ab652dd3
commit
412b7595d2
@ -7,6 +7,7 @@ import splitByGroups from "../../../common/entity/split_by_groups";
|
|||||||
import computeObjectId from "../../../common/entity/compute_object_id";
|
import computeObjectId from "../../../common/entity/compute_object_id";
|
||||||
import computeStateDomain from "../../../common/entity/compute_state_domain";
|
import computeStateDomain from "../../../common/entity/compute_state_domain";
|
||||||
import { LocalizeFunc } from "../../../mixins/localize-base-mixin";
|
import { LocalizeFunc } from "../../../mixins/localize-base-mixin";
|
||||||
|
import computeDomain from "../../../common/entity/compute_domain";
|
||||||
|
|
||||||
interface CardConfig {
|
interface CardConfig {
|
||||||
id?: string;
|
id?: string;
|
||||||
@ -39,38 +40,42 @@ const DOMAINS_BADGES = [
|
|||||||
];
|
];
|
||||||
const HIDE_DOMAIN = new Set(["persistent_notification", "configurator"]);
|
const HIDE_DOMAIN = new Set(["persistent_notification", "configurator"]);
|
||||||
|
|
||||||
const computeCards = (title: string, states: HassEntity[]): CardConfig[] => {
|
const computeCards = (
|
||||||
|
title: string,
|
||||||
|
states: Array<[string, HassEntity]>
|
||||||
|
): CardConfig[] => {
|
||||||
const cards: CardConfig[] = [];
|
const cards: CardConfig[] = [];
|
||||||
|
|
||||||
// For entity card
|
// For entity card
|
||||||
const entities: string[] = [];
|
const entities: string[] = [];
|
||||||
|
|
||||||
states.forEach((stateObj) => {
|
for (const [entityId /*, stateObj */] of states) {
|
||||||
const domain = computeStateDomain(stateObj);
|
const domain = computeDomain(entityId);
|
||||||
|
|
||||||
if (domain === "alarm_control_panel") {
|
if (domain === "alarm_control_panel") {
|
||||||
cards.push({
|
cards.push({
|
||||||
type: "alarm-panel",
|
type: "alarm-panel",
|
||||||
entity: stateObj.entity_id,
|
entity: entityId,
|
||||||
});
|
});
|
||||||
} else if (domain === "climate") {
|
} else if (domain === "climate") {
|
||||||
cards.push({
|
cards.push({
|
||||||
type: "thermostat",
|
type: "thermostat",
|
||||||
entity: stateObj.entity_id,
|
entity: entityId,
|
||||||
});
|
});
|
||||||
} else if (domain === "media_player") {
|
} else if (domain === "media_player") {
|
||||||
cards.push({
|
cards.push({
|
||||||
type: "media-control",
|
type: "media-control",
|
||||||
entity: stateObj.entity_id,
|
entity: entityId,
|
||||||
});
|
});
|
||||||
} else if (domain === "weather") {
|
} else if (domain === "weather") {
|
||||||
cards.push({
|
cards.push({
|
||||||
type: "weather-forecast",
|
type: "weather-forecast",
|
||||||
entity: stateObj.entity_id,
|
entity: entityId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
entities.push(stateObj.entity_id);
|
entities.push(entityId);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
if (entities.length > 0) {
|
if (entities.length > 0) {
|
||||||
cards.unshift({
|
cards.unshift({
|
||||||
@ -142,7 +147,9 @@ const generateViewConfig = (
|
|||||||
cards = cards.concat(
|
cards = cards.concat(
|
||||||
computeCards(
|
computeCards(
|
||||||
computeStateName(groupEntity),
|
computeStateName(groupEntity),
|
||||||
groupEntity.attributes.entity_id.map((entityId) => entities[entityId])
|
groupEntity.attributes.entity_id.map(
|
||||||
|
(entityId): [string, HassEntity] => [entityId, entities[entityId]]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -153,7 +160,9 @@ const generateViewConfig = (
|
|||||||
cards = cards.concat(
|
cards = cards.concat(
|
||||||
computeCards(
|
computeCards(
|
||||||
localize(`domain.${domain}`),
|
localize(`domain.${domain}`),
|
||||||
ungroupedEntitites[domain].map((entityId) => entities[entityId])
|
ungroupedEntitites[domain].map(
|
||||||
|
(entityId): [string, HassEntity] => [entityId, entities[entityId]]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user