Avoid linear search of entity registry in ruckus_unleashed (#109643)

pull/109406/head
J. Nick Koston 2024-02-04 14:20:55 -06:00 committed by GitHub
parent 74812261d4
commit 6003ae149a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 5 deletions

View File

@ -18,6 +18,7 @@ from .const import (
KEY_SYS_CLIENTS,
UNDO_UPDATE_LISTENERS,
)
from .coordinator import RuckusUnleashedDataUpdateCoordinator
_LOGGER = logging.getLogger(__package__)
@ -65,14 +66,19 @@ def add_new_entities(coordinator, async_add_entities, tracked):
@callback
def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
def restore_entities(
registry: er.EntityRegistry,
coordinator: RuckusUnleashedDataUpdateCoordinator,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
tracked: set[str],
) -> None:
"""Restore clients that are not a part of active clients list."""
missing = []
missing: list[RuckusUnleashedDevice] = []
for entity in registry.entities.values():
for entity in registry.entities.get_entries_for_config_entry_id(entry.entry_id):
if (
entity.config_entry_id == entry.entry_id
and entity.platform == DOMAIN
entity.platform == DOMAIN
and entity.unique_id not in coordinator.data[KEY_SYS_CLIENTS]
):
missing.append(