mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Use a filter for the PersonStorageCollection EVENT_ENTITY_REGISTRY_UPDATED listener (#89335)
Avoids creating a task unless a device_tracker is removed
This commit is contained in:
parent
008a30618c
commit
3e5e937541
@ -226,19 +226,22 @@ class PersonStorageCollection(collection.StorageCollection):
|
|||||||
"""Load the Storage collection."""
|
"""Load the Storage collection."""
|
||||||
await super().async_load()
|
await super().async_load()
|
||||||
self.hass.bus.async_listen(
|
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."""
|
"""Handle entity registry updated."""
|
||||||
if event.data["action"] != "remove":
|
|
||||||
return
|
|
||||||
|
|
||||||
entity_id = event.data[ATTR_ENTITY_ID]
|
entity_id = event.data[ATTR_ENTITY_ID]
|
||||||
|
|
||||||
if split_entity_id(entity_id)[0] != "device_tracker":
|
|
||||||
return
|
|
||||||
|
|
||||||
for person in list(self.data.values()):
|
for person in list(self.data.values()):
|
||||||
if entity_id not in person[CONF_DEVICE_TRACKERS]:
|
if entity_id not in person[CONF_DEVICE_TRACKERS]:
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user