Update card is entity in condition change
This commit is contained in:
parent
c6fe79eee8
commit
efdabfc8a4
|
@ -6,6 +6,7 @@ import { processConfigEntities } from "../common/process-config-entities";
|
|||
import {
|
||||
addEntityToCondition,
|
||||
checkConditionsMet,
|
||||
extractConditionEntityIds,
|
||||
} from "../common/validate-condition";
|
||||
import { createBadgeElement } from "../create-element/create-badge-element";
|
||||
import { EntityFilterEntityConfig } from "../entity-rows/types";
|
||||
|
@ -155,8 +156,24 @@ export class HuiEntityFilterBadge
|
|||
if (this.hass.states[config.entity] !== oldHass.states[config.entity]) {
|
||||
return true;
|
||||
}
|
||||
if (config.conditions) {
|
||||
const entityIds = extractConditionEntityIds(config.conditions);
|
||||
for (const entityId of entityIds) {
|
||||
if (this.hass.states[entityId] !== oldHass.states[entityId]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._config?.conditions) {
|
||||
const entityIds = extractConditionEntityIds(this._config?.conditions);
|
||||
for (const entityId of entityIds) {
|
||||
if (this.hass.states[entityId] !== oldHass.states[entityId]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { processConfigEntities } from "../common/process-config-entities";
|
|||
import {
|
||||
addEntityToCondition,
|
||||
checkConditionsMet,
|
||||
extractConditionEntityIds,
|
||||
} from "../common/validate-condition";
|
||||
import { createCardElement } from "../create-element/create-card-element";
|
||||
import { EntityFilterEntityConfig } from "../entity-rows/types";
|
||||
|
@ -212,6 +213,23 @@ export class HuiEntityFilterCard
|
|||
if (this.hass.states[config.entity] !== oldHass.states[config.entity]) {
|
||||
return true;
|
||||
}
|
||||
if (config.conditions) {
|
||||
const entityIds = extractConditionEntityIds(config.conditions);
|
||||
for (const entityId of entityIds) {
|
||||
if (this.hass.states[entityId] !== oldHass.states[entityId]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._config?.conditions) {
|
||||
const entityIds = extractConditionEntityIds(this._config?.conditions);
|
||||
for (const entityId of entityIds) {
|
||||
if (this.hass.states[entityId] !== oldHass.states[entityId]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -180,6 +180,23 @@ export function checkConditionsMet(
|
|||
});
|
||||
}
|
||||
|
||||
export function extractConditionEntityIds(conditions: Condition[]): string[] {
|
||||
const entityIds: string[] = [];
|
||||
for (const condition of conditions) {
|
||||
if (condition.condition === "numeric_state") {
|
||||
if (typeof condition.above === "string") {
|
||||
entityIds.push(condition.above);
|
||||
}
|
||||
if (typeof condition.below === "string") {
|
||||
entityIds.push(condition.below);
|
||||
}
|
||||
} else if ("conditions" in condition && condition.conditions) {
|
||||
entityIds.push(...extractConditionEntityIds(condition.conditions));
|
||||
}
|
||||
}
|
||||
return entityIds;
|
||||
}
|
||||
|
||||
function validateStateCondition(condition: StateCondition | LegacyCondition) {
|
||||
return (
|
||||
condition.entity != null &&
|
||||
|
|
Loading…
Reference in New Issue