Entity Cleanup on Z-Wave node removal (#23633)
* Initial groundwork for entity cleanup on node removal * Connect node_removed to dispatcher * update docstring * Add node_removal test * Address review comments * Use hass.add_job instead of run_coroutine_threadsafe
This commit is contained in:
1 parent
eebd094423
commit
1282370ccb
3 files changed
+74
No files matched your search
@@ -3,6 +3,7 @@ import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_WAKEUP, ATTR_ENTITY_ID
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import (
|
||||
@@ -74,6 +75,16 @@ class ZWaveBaseEntity(Entity):
|
||||
if self.hass and self.platform:
|
||||
self.hass.add_job(_async_remove_and_add)
|
||||
|
||||
async def node_removed(self):
|
||||
"""Call when a node is removed from the Z-Wave network."""
|
||||
await self.async_remove()
|
||||
|
||||
registry = await async_get_registry(self.hass)
|
||||
if self.entity_id not in registry.entities:
|
||||
return
|
||||
|
||||
registry.async_remove(self.entity_id)
|
||||
|
||||
|
||||
class ZWaveNodeEntity(ZWaveBaseEntity):
|
||||
"""Representation of a Z-Wave node."""
|
||||
|
||||
Reference in new issue
Block a user