mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 20:56:36 +00:00
Refactor get value from entity id
This commit is contained in:
parent
552eeeddf6
commit
52fdbfe44c
@ -56,18 +56,9 @@ export interface AndCondition extends BaseCondition {
|
|||||||
conditions?: Condition[];
|
conditions?: Condition[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValueFromEntityId(
|
function getValueFromEntityId(hass: HomeAssistant, value: string): string {
|
||||||
hass: HomeAssistant,
|
if (isValidEntityId(value) && hass.states[value]) {
|
||||||
value: string | string[]
|
return hass.states[value]?.state;
|
||||||
): string | string[] {
|
|
||||||
if (
|
|
||||||
typeof value === "string" &&
|
|
||||||
isValidEntityId(value) &&
|
|
||||||
hass.states[value]
|
|
||||||
) {
|
|
||||||
value = hass.states[value]?.state;
|
|
||||||
} else if (Array.isArray(value)) {
|
|
||||||
value = value.map((v) => getValueFromEntityId(hass, v) as string);
|
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -83,9 +74,12 @@ function checkStateCondition(
|
|||||||
let value = condition.state ?? condition.state_not;
|
let value = condition.state ?? condition.state_not;
|
||||||
|
|
||||||
// Handle entity_id, UI should be updated for conditionnal card (filters does not have UI for now)
|
// Handle entity_id, UI should be updated for conditionnal card (filters does not have UI for now)
|
||||||
if (Array.isArray(value) || typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
value = getValueFromEntityId(hass, value);
|
value = getValueFromEntityId(hass, value);
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value = value.map((val) => getValueFromEntityId(hass, val));
|
||||||
|
}
|
||||||
|
|
||||||
return condition.state != null
|
return condition.state != null
|
||||||
? ensureArray(value).includes(state)
|
? ensureArray(value).includes(state)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user