From 64a1d02e6cee6372fda904e9679aa219a95920a4 Mon Sep 17 00:00:00 2001 From: Jason <37859597+zachowj@users.noreply.github.com> Date: Sun, 18 Aug 2024 15:51:24 -0700 Subject: [PATCH] fix(get-entities): Iterate over 'states' table to retrieve all entities Some entities are not listed in the entity registry. This change ensures all entities are captured by using the 'states' table for the search. Fixes #1481 --- .../get-entities/GetEntitiesController.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/nodes/get-entities/GetEntitiesController.ts b/src/nodes/get-entities/GetEntitiesController.ts index ad84f23877..b012295e04 100644 --- a/src/nodes/get-entities/GetEntitiesController.ts +++ b/src/nodes/get-entities/GetEntitiesController.ts @@ -154,15 +154,12 @@ export default class GetEntitiesController extends SendSplitController { const states = this.#homeAssistant.websocket.getStates(); const sortedConditions = sortConditions(conditions); - for (const entity of entities) { - // disabled entities don't have a state object - if (entity.disabled_by !== null) { - continue; - } - + for (const state of Object.values(states) as HassEntity[]) { this.#resetCurrent(); - const state = states[entity.entity_id] as HassEntity; + const entity = entities.find( + (e) => e.entity_id === state.entity_id, + ); let ruleMatched = true; for (const rule of sortedConditions) { @@ -196,6 +193,11 @@ export default class GetEntitiesController extends SendSplitController { break; } } else if (rule.condition === PropertySelectorType.Label) { + if (!entity) { + ruleMatched = false; + break; + } + if (entity.labels.length === 0) { ruleMatched = false; break; @@ -233,6 +235,11 @@ export default class GetEntitiesController extends SendSplitController { break; } } else { + if (!entity) { + ruleMatched = false; + break; + } + let propertyValue: unknown; if (rule.condition === PropertySelectorType.Device) { const device = this.#getDevice(entity);