Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Jun 26, 2024
1 parent 373a0ad commit 88f73d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
28 changes: 11 additions & 17 deletions src/data/device_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,34 +146,28 @@ export const getDeviceIntegrationLookup = (
entities: EntityRegistryDisplayEntry[] | EntityRegistryEntry[],
devices?: DeviceRegistryEntry[],
configEntries?: ConfigEntry[]
): Record<string, string[]> => {
const deviceIntegrations: Record<string, string[]> = {};
): Record<string, Set<string>> => {
const deviceIntegrations: Record<string, Set<string>> = {};

for (const entity of entities) {
const source = entitySources[entity.entity_id];
if (!source?.domain || entity.device_id === null) {
continue;
}

if (!deviceIntegrations[entity.device_id!]) {
deviceIntegrations[entity.device_id!] = [];
}
deviceIntegrations[entity.device_id!].push(source.domain);
deviceIntegrations[entity.device_id!] =
deviceIntegrations[entity.device_id!] || new Set<string>();
deviceIntegrations[entity.device_id!].add(source.domain);
}
// Lookup devices that have no entities
if (devices && configEntries) {
for (const device of devices) {
if (!deviceIntegrations[device.id]) {
for (const config_entry_id of device.config_entries) {
const entry = configEntries.find(
(e) => e.entry_id === config_entry_id
);
if (entry?.domain) {
(
deviceIntegrations[device.id] ||
(deviceIntegrations[device.id] = [])
).push(entry.domain);
}
for (const config_entry_id of device.config_entries) {
const entry = configEntries.find((e) => e.entry_id === config_entry_id);
if (entry?.domain) {
deviceIntegrations[device.id] =
deviceIntegrations[device.id] || new Set<string>();
deviceIntegrations[device.id].add(entry.domain);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ export const entityMeetsTargetSelector = (
export const filterSelectorDevices = (
filterDevice: DeviceSelectorFilter,
device: DeviceRegistryEntry,
deviceIntegrationLookup?: Record<string, string[]> | undefined
deviceIntegrationLookup?: Record<string, Set<string>> | undefined
): boolean => {
const {
manufacturer: filterManufacturer,
Expand All @@ -713,7 +713,7 @@ export const filterSelectorDevices = (
}

if (filterIntegration && deviceIntegrationLookup) {
if (!deviceIntegrationLookup?.[device.id]?.includes(filterIntegration)) {
if (!deviceIntegrationLookup?.[device.id]?.has(filterIntegration)) {
return false;
}
}
Expand Down

0 comments on commit 88f73d7

Please sign in to comment.