Avoid linear search of entity registry in async_get_device_automations (#109633)

This commit is contained in:
J. Nick Koston 2024-02-04 14:22:12 -06:00 committed by GitHub
parent 6003ae149a
commit f37db94f23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -247,9 +247,10 @@ async def async_get_device_automations(
match_device_ids = set(device_ids or device_registry.devices)
combined_results: dict[str, list[dict[str, Any]]] = {}
for entry in entity_registry.entities.values():
if not entry.disabled_by and entry.device_id in match_device_ids:
device_entities_domains.setdefault(entry.device_id, set()).add(entry.domain)
for device_id in match_device_ids:
for entry in entity_registry.entities.get_entries_for_device_id(device_id):
if not entry.disabled_by:
device_entities_domains.setdefault(device_id, set()).add(entry.domain)
for device_id in match_device_ids:
combined_results[device_id] = []