Use a filter for the PersonStorageCollection EVENT_ENTITY_REGISTRY_UPDATED listener (#89335)
Avoids creating a task unless a device_tracker is removedpull/89341/head^2
parent
008a30618c
commit
3e5e937541
|
@ -226,19 +226,22 @@ class PersonStorageCollection(collection.StorageCollection):
|
|||
"""Load the Storage collection."""
|
||||
await super().async_load()
|
||||
self.hass.bus.async_listen(
|
||||
er.EVENT_ENTITY_REGISTRY_UPDATED, self._entity_registry_updated
|
||||
er.EVENT_ENTITY_REGISTRY_UPDATED,
|
||||
self._entity_registry_updated,
|
||||
event_filter=self._entity_registry_filter,
|
||||
)
|
||||
|
||||
async def _entity_registry_updated(self, event) -> None:
|
||||
@callback
|
||||
def _entity_registry_filter(self, event: Event) -> bool:
|
||||
"""Filter entity registry events."""
|
||||
return (
|
||||
event.data["action"] == "remove"
|
||||
and split_entity_id(event.data[ATTR_ENTITY_ID])[0] == "device_tracker"
|
||||
)
|
||||
|
||||
async def _entity_registry_updated(self, event: Event) -> None:
|
||||
"""Handle entity registry updated."""
|
||||
if event.data["action"] != "remove":
|
||||
return
|
||||
|
||||
entity_id = event.data[ATTR_ENTITY_ID]
|
||||
|
||||
if split_entity_id(entity_id)[0] != "device_tracker":
|
||||
return
|
||||
|
||||
for person in list(self.data.values()):
|
||||
if entity_id not in person[CONF_DEVICE_TRACKERS]:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue