Skip to content

Commit

Permalink
fix: Fix ID selector to include state only entities
Browse files Browse the repository at this point in the history
  • Loading branch information
zachowj committed Aug 26, 2024
1 parent c9c837b commit 8057dd7
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/editor/components/idSelector/IdSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export default class IdSelector {

#createTargetData(): TargetData {
const entityRegistry = haServer.getEntityRegistry();
const entities = haServer.getEntities();
const states = haServer.getEntities();
const devices = haServer.getDevices();
const areas = haServer.getAreas();
const floors = haServer.getFloors();
const labels = haServer.getLabels();

if (this.#filter.length === 0) {
return {
entities,
entities: states,
devices,
areas,
floors,
Expand All @@ -87,25 +87,22 @@ export default class IdSelector {
supported_features: supportedFeatures,
} = filter;

for (const entity of entityRegistry) {
// Skip disabled entities
if (entity.disabled_by !== null) {
continue;
}
for (const state of states) {
const entity = entityRegistry.find(
(e) => e.entity_id === state.entity_id,
);

// Skip entities that are not part of the integration
if (integration && entity.platform !== integration) {
if (integration && entity?.platform !== integration) {
continue;
}

// Skip entities that are not part of the domain
const entityDomain = entity.entity_id.split('.')[0];
const entityDomain = state.entity_id.split('.')[0];
if (domain?.length && !domain.includes(entityDomain)) {
continue;
}

const state = haServer.getEntity(entity.entity_id);

// Skip entities that are not part of the device class
if (
deviceClass?.length &&
Expand All @@ -126,6 +123,13 @@ export default class IdSelector {
continue;
}

filteredEntities.push(state);

// Skip the rest of the checks if the entity is not part of the registry
if (!entity) {
continue;
}

// Add devices that the entity is part of
let device: HassDevice | undefined;
if (entity.device_id) {
Expand Down Expand Up @@ -164,8 +168,6 @@ export default class IdSelector {
}
}
}

filteredEntities.push(state);
}
}

Expand Down

0 comments on commit 8057dd7

Please sign in to comment.