Index entity_registry_updated listeners (#37940)

This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-07-17 21:59:18 -07:00
1 parent 9ae08585dc
commit 910b6c9c2c
4 files changed
+189 -19

No files matched your search

+6 -12
View File
@@ -27,11 +27,8 @@ from homeassistant.const import (
from homeassistant.core import CALLBACK_TYPE, Context, HomeAssistant, callback
from homeassistant.exceptions import NoEntitySpecifiedError
from homeassistant.helpers.entity_platform import EntityPlatform
from homeassistant.helpers.entity_registry import (
EVENT_ENTITY_REGISTRY_UPDATED,
RegistryEntry,
)
from homeassistant.helpers.event import Event
from homeassistant.helpers.entity_registry import RegistryEntry
from homeassistant.helpers.event import Event, async_track_entity_registry_updated_event
from homeassistant.util import dt as dt_util, ensure_unique_string, slugify
from homeassistant.util.async_ import run_callback_threadsafe
@@ -518,8 +515,8 @@ class Entity(ABC):
if self.registry_entry is not None:
assert self.hass is not None
self.async_on_remove(
self.hass.bus.async_listen(
EVENT_ENTITY_REGISTRY_UPDATED, self._async_registry_updated
async_track_entity_registry_updated_event(
self.hass, self.entity_id, self._async_registry_updated
)
)
@@ -532,14 +529,11 @@ class Entity(ABC):
async def _async_registry_updated(self, event: Event) -> None:
"""Handle entity registry update."""
data = event.data
if data["action"] == "remove" and data["entity_id"] == self.entity_id:
if data["action"] == "remove":
await self.async_removed_from_registry()
await self.async_remove()
if (
data["action"] != "update"
or data.get("old_entity_id", data["entity_id"]) != self.entity_id
):
if data["action"] != "update":
return
assert self.hass is not None