Skip to content

Commit

Permalink
fix(get-entities): Iterate over 'states' table to retrieve all entities
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zachowj committed Aug 18, 2024
1 parent 495d42d commit 64a1d02
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/nodes/get-entities/GetEntitiesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 64a1d02

Please sign in to comment.