Avoid linear search of entity registry in keenetic_ndms2 (#109635)

This commit is contained in:
J. Nick Koston 2024-02-04 14:12:24 -06:00 committed by GitHub
parent c988d3d427
commit 6ccf82d7b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 10 deletions

View File

@ -75,11 +75,10 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
for mac, device in router.last_devices.items() for mac, device in router.last_devices.items()
if device.interface in new_tracked_interfaces if device.interface in new_tracked_interfaces
} }
for entity_entry in list(ent_reg.entities.values()): for entity_entry in ent_reg.entities.get_entries_for_config_entry_id(
if ( config_entry.entry_id
entity_entry.config_entry_id == config_entry.entry_id ):
and entity_entry.domain == Platform.DEVICE_TRACKER if entity_entry.domain == Platform.DEVICE_TRACKER:
):
mac = entity_entry.unique_id.partition("_")[0] mac = entity_entry.unique_id.partition("_")[0]
if mac not in keep_devices: if mac not in keep_devices:
_LOGGER.debug("Removing entity %s", entity_entry.entity_id) _LOGGER.debug("Removing entity %s", entity_entry.entity_id)

View File

@ -43,11 +43,10 @@ async def async_setup_entry(
registry = er.async_get(hass) registry = er.async_get(hass)
# Restore devices that are not a part of active clients list. # Restore devices that are not a part of active clients list.
restored = [] restored = []
for entity_entry in registry.entities.values(): for entity_entry in registry.entities.get_entries_for_config_entry_id(
if ( config_entry.entry_id
entity_entry.config_entry_id == config_entry.entry_id ):
and entity_entry.domain == DEVICE_TRACKER_DOMAIN if entity_entry.domain == DEVICE_TRACKER_DOMAIN:
):
mac = entity_entry.unique_id.partition("_")[0] mac = entity_entry.unique_id.partition("_")[0]
if mac not in tracked: if mac not in tracked:
tracked.add(mac) tracked.add(mac)