Track entity sources (#37258)
Co-authored-by: David Mulcahey <david.mulcahey@me.com>
This commit is contained in:
1 parent
24a16ff8fe
commit
3dc79aa60a
15 files changed
+379
-154
No files matched your search
@@ -77,11 +77,6 @@ class DeconzDevice(DeconzBase, Entity):
|
||||
self.hass, self.gateway.signal_reachable, self.async_update_callback
|
||||
)
|
||||
)
|
||||
self.listeners.append(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self.gateway.signal_remove_entity, self.async_remove_self
|
||||
)
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Disconnect device object when removed."""
|
||||
@@ -91,15 +86,6 @@ class DeconzDevice(DeconzBase, Entity):
|
||||
for unsub_dispatcher in self.listeners:
|
||||
unsub_dispatcher()
|
||||
|
||||
async def async_remove_self(self, deconz_ids: list) -> None:
|
||||
"""Schedule removal of this entity.
|
||||
|
||||
Called by signal_remove_entity scheduled by async_added_to_hass.
|
||||
"""
|
||||
if self._device.deconz_id not in deconz_ids:
|
||||
return
|
||||
await self.async_remove()
|
||||
|
||||
@callback
|
||||
def async_update_callback(self, force_update=False, ignore_update=False):
|
||||
"""Update the device's state."""
|
||||
|
||||
@@ -164,15 +164,14 @@ class DeconzGateway:
|
||||
else:
|
||||
deconz_ids += [group.deconz_id for group in groups]
|
||||
|
||||
if deconz_ids:
|
||||
async_dispatcher_send(self.hass, self.signal_remove_entity, deconz_ids)
|
||||
|
||||
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
for entity_id, deconz_id in self.deconz_ids.items():
|
||||
if deconz_id in deconz_ids and entity_registry.async_is_registered(
|
||||
entity_id
|
||||
):
|
||||
# Removing an entity from the entity registry will also remove them
|
||||
# from Home Assistant
|
||||
entity_registry.async_remove(entity_id)
|
||||
|
||||
@property
|
||||
@@ -197,11 +196,6 @@ class DeconzGateway:
|
||||
}
|
||||
return new_device[device_type]
|
||||
|
||||
@property
|
||||
def signal_remove_entity(self) -> str:
|
||||
"""Gateway specific event to signal removal of entity."""
|
||||
return f"deconz-remove-{self.bridgeid}"
|
||||
|
||||
@callback
|
||||
def async_add_device_callback(self, device_type, device) -> None:
|
||||
"""Handle event of new device creation in deCONZ."""
|
||||
|
||||
Reference in new issue
Block a user