mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 13:07:49 +00:00
Use set instead of list
This commit is contained in:
parent
c43c06d6e6
commit
d03449c60a
@ -180,24 +180,38 @@ export function checkConditionsMet(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractConditionEntityIds(conditions: Condition[]): string[] {
|
export function extractConditionEntityIds(
|
||||||
const entityIds: string[] = [];
|
conditions: Condition[]
|
||||||
|
): Set<string> {
|
||||||
|
const entityIds: Set<string> = new Set();
|
||||||
for (const condition of conditions) {
|
for (const condition of conditions) {
|
||||||
if (condition.condition === "numeric_state") {
|
if (condition.condition === "numeric_state") {
|
||||||
if (
|
if (
|
||||||
typeof condition.above === "string" &&
|
typeof condition.above === "string" &&
|
||||||
isValidEntityId(condition.above)
|
isValidEntityId(condition.above)
|
||||||
) {
|
) {
|
||||||
entityIds.push(condition.above);
|
entityIds.add(condition.above);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
typeof condition.below === "string" &&
|
typeof condition.below === "string" &&
|
||||||
isValidEntityId(condition.below)
|
isValidEntityId(condition.below)
|
||||||
) {
|
) {
|
||||||
entityIds.push(condition.below);
|
entityIds.add(condition.below);
|
||||||
}
|
}
|
||||||
|
} else if (condition.condition === "state") {
|
||||||
|
[
|
||||||
|
...ensureArray(condition.state),
|
||||||
|
...ensureArray(condition.state_not),
|
||||||
|
].forEach((state) => {
|
||||||
|
if (!!state && isValidEntityId(state)) {
|
||||||
|
entityIds.add(state);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if ("conditions" in condition && condition.conditions) {
|
} else if ("conditions" in condition && condition.conditions) {
|
||||||
entityIds.push(...extractConditionEntityIds(condition.conditions));
|
return new Set([
|
||||||
|
...entityIds,
|
||||||
|
...extractConditionEntityIds(condition.conditions),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return entityIds;
|
return entityIds;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user