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
@@ -376,6 +376,25 @@ async def async_setup_entry(hass, config_entry):
|
||||
hass.add_job(check_has_unique_id, entity, _on_ready, _on_timeout,
|
||||
hass.loop)
|
||||
|
||||
def node_removed(node):
|
||||
node_id = node.node_id
|
||||
node_key = 'node-{}'.format(node_id)
|
||||
_LOGGER.info("Node Removed: %s",
|
||||
hass.data[DATA_DEVICES][node_key])
|
||||
for key in list(hass.data[DATA_DEVICES]):
|
||||
if not key.startswith('{}-'.format(node_id)):
|
||||
continue
|
||||
|
||||
entity = hass.data[DATA_DEVICES][key]
|
||||
_LOGGER.info('Removing Entity - value: %s - entity_id: %s',
|
||||
key, entity.entity_id)
|
||||
hass.add_job(entity.node_removed())
|
||||
del hass.data[DATA_DEVICES][key]
|
||||
|
||||
entity = hass.data[DATA_DEVICES][node_key]
|
||||
hass.add_job(entity.node_removed())
|
||||
del hass.data[DATA_DEVICES][node_key]
|
||||
|
||||
def network_ready():
|
||||
"""Handle the query of all awake nodes."""
|
||||
_LOGGER.info("Z-Wave network is ready for use. All awake nodes "
|
||||
@@ -399,6 +418,8 @@ async def async_setup_entry(hass, config_entry):
|
||||
value_added, ZWaveNetwork.SIGNAL_VALUE_ADDED, weak=False)
|
||||
dispatcher.connect(
|
||||
node_added, ZWaveNetwork.SIGNAL_NODE_ADDED, weak=False)
|
||||
dispatcher.connect(
|
||||
node_removed, ZWaveNetwork.SIGNAL_NODE_REMOVED, weak=False)
|
||||
dispatcher.connect(
|
||||
network_ready, ZWaveNetwork.SIGNAL_AWAKE_NODES_QUERIED, weak=False)
|
||||
dispatcher.connect(
|
||||
|
||||
Reference in new issue
Block a user