mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
Tweak rules for entity-filter card (#25570)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
114c1fb98b
commit
9f5f100e98
@ -82,18 +82,40 @@ export class HuiEntityFilterCard
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!(
|
!config.conditions &&
|
||||||
(config.conditions && Array.isArray(config.conditions)) ||
|
!config.state_filter &&
|
||||||
(config.state_filter && Array.isArray(config.state_filter))
|
!config.entities.some(
|
||||||
) &&
|
|
||||||
!config.entities.every(
|
|
||||||
(entity) =>
|
(entity) =>
|
||||||
typeof entity === "object" &&
|
typeof entity === "object" &&
|
||||||
entity.state_filter &&
|
(entity.state_filter || entity.conditions)
|
||||||
Array.isArray(entity.state_filter)
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new Error("Incorrect filter config");
|
throw new Error("At least one conditions or state_filter is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(config.conditions && !Array.isArray(config.conditions)) ||
|
||||||
|
(config.state_filter && !Array.isArray(config.state_filter)) ||
|
||||||
|
config.entities.some(
|
||||||
|
(entity) =>
|
||||||
|
typeof entity === "object" &&
|
||||||
|
((entity.state_filter && !Array.isArray(entity.state_filter)) ||
|
||||||
|
(entity.conditions && !Array.isArray(entity.conditions)))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new Error("Conditions or state_filter must be an array");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(config.conditions && config.state_filter) ||
|
||||||
|
config.entities.some(
|
||||||
|
(entity) =>
|
||||||
|
typeof entity === "object" && entity.state_filter && entity.conditions
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
"Conditions and state_filter may not be simultaneously defined"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._configEntities = processConfigEntities(config.entities);
|
this._configEntities = processConfigEntities(config.entities);
|
||||||
@ -149,7 +171,7 @@ export class HuiEntityFilterCard
|
|||||||
if (!stateObj) return false;
|
if (!stateObj) return false;
|
||||||
|
|
||||||
const conditions = entityConf.conditions ?? this._config!.conditions;
|
const conditions = entityConf.conditions ?? this._config!.conditions;
|
||||||
if (conditions) {
|
if (conditions && !entityConf.state_filter) {
|
||||||
const conditionWithEntity = conditions.map((condition) =>
|
const conditionWithEntity = conditions.map((condition) =>
|
||||||
addEntityToCondition(condition, entityConf.entity)
|
addEntityToCondition(condition, entityConf.entity)
|
||||||
);
|
);
|
||||||
@ -161,7 +183,7 @@ export class HuiEntityFilterCard
|
|||||||
return filters.some((filter) => evaluateStateFilter(stateObj, filter));
|
return filters.some((filter) => evaluateStateFilter(stateObj, filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (entitiesList.length === 0 && this._config.show_empty === false) {
|
if (entitiesList.length === 0 && this._config.show_empty === false) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user