Skip to content

Commit

Permalink
Added device disconnection on updating active connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Feb 6, 2025
1 parent db93fca commit 49d12bb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,11 @@ def _handle_active_connectors_update(self, config):
for active_connector_name in self._gateway.available_connectors_by_name:
if active_connector_name not in config:
try:
self._gateway.available_connectors_by_name[active_connector_name].close()
connector_id = self._gateway.available_connectors_by_name[active_connector_name].get_id()
connector_to_close = self._gateway.available_connectors_by_name[active_connector_name]
connector_to_close.close()
for device in self._gateway.get_connector_devices(connector_to_close):
self._gateway.del_device(device)
connector_id = connector_to_close.get_id()
self._gateway.available_connectors_by_id.pop(connector_id)
for_deletion.append(active_connector_name)
for_deletion_ids.append(connector_id)
Expand Down Expand Up @@ -677,7 +680,7 @@ def _handle_connector_configuration_update(self, config):
retrieved_connector.close()
if self._gateway.tb_client.is_connected():
for device in self._gateway.get_connector_devices(retrieved_connector):
self.del_device(device)
self._gateway.del_device(device)
self._gateway.clean_shared_attributes_cache_for_connector_devices(retrieved_connector)
if monotonic() - close_start > 5:
self.__log.error('Connector %s not stopped in 5 seconds', connector_configuration['id']) # noqa
Expand All @@ -692,7 +695,7 @@ def _handle_connector_configuration_update(self, config):
retrieved_connector.close()
if self._gateway.tb_client.is_connected():
for device in self._gateway.get_connector_devices(retrieved_connector):
self.del_device(device)
self._gateway.del_device(device)
self._gateway.clean_shared_attributes_cache_for_connector_devices(retrieved_connector)
if monotonic() - close_start > 5:
self.__log.error('Connector %s not stopped in 5 seconds',
Expand Down

0 comments on commit 49d12bb

Please sign in to comment.