Avoid linear search of the entity registry in ps4 (#109723)

pull/109767/head
J. Nick Koston 2024-02-05 16:25:12 -06:00 committed by GitHub
parent 440212ddce
commit 6fce8a5403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 29 deletions

View File

@ -120,9 +120,11 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Prevent changing entity_id. Updates entity registry.
registry = er.async_get(hass)
for entity_id, e_entry in registry.entities.items():
if e_entry.config_entry_id == entry.entry_id:
for e_entry in registry.entities.get_entries_for_config_entry_id(
entry.entry_id
):
unique_id = e_entry.unique_id
entity_id = e_entry.entity_id
# Remove old entity entry.
registry.async_remove(entity_id)

View File

@ -344,10 +344,12 @@ class PS4Device(MediaPlayerEntity):
_LOGGER.info("Assuming status from registry")
e_registry = er.async_get(self.hass)
d_registry = dr.async_get(self.hass)
for entity_id, entry in e_registry.entities.items():
if entry.config_entry_id == self._entry_id:
for entry in e_registry.entities.get_entries_for_config_entry_id(
self._entry_id
):
self._attr_unique_id = entry.unique_id
self.entity_id = entity_id
self.entity_id = entry.entity_id
break
for device in d_registry.devices.values():
if self._entry_id in device.config_entries: