1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Fixed handling active connectors request

This commit is contained in:
samson0v
2023-09-18 13:43:50 +03:00
parent 9f98173b5a
commit 6150be0acd
3 changed files with 29 additions and 12 deletions

View File

@@ -788,13 +788,17 @@ class TBGatewayService:
try:
if connector_config["config"][config] is not None:
connector_name = connector_config["name"]
connector = self._implemented_connectors[connector_type](self,
connector_config["config"][
config],
connector_type)
connector.setName(connector_name)
self.available_connectors[connector.get_name()] = connector
connector.open()
if not self.available_connectors.get(connector_name):
connector = self._implemented_connectors[connector_type](self,
connector_config["config"][
config],
connector_type)
connector.setName(connector_name)
self.available_connectors[connector.get_name()] = connector
connector.open()
else:
break
else:
log.info("Config not found for %s", connector_type)
except Exception as e:

View File

@@ -337,17 +337,26 @@ class RemoteConfigurator:
def _handle_active_connectors_update(self, config):
LOG.debug('Processing active connectors configuration update...')
has_changed = False
for_deletion = []
for active_connector_name in self._gateway.available_connectors:
if active_connector_name not in config:
try:
self._gateway.available_connectors[active_connector_name].close()
for_deletion.append(active_connector_name)
has_changed = True
except Exception as e:
LOG.exception(e)
self._delete_connectors_from_config(config)
with open(self._gateway.get_config_path() + 'tb_gateway.json', 'w') as file:
file.writelines(dumps(self._get_tb_gateway_general_config_for_save(), indent=' '))
self._active_connectors = config
if has_changed:
for name in for_deletion:
self._gateway.available_connectors.pop(name)
self._delete_connectors_from_config(config)
with open(self._gateway.get_config_path() + 'tb_gateway.json', 'w') as file:
file.writelines(dumps(self._get_tb_gateway_general_config_for_save(), indent=' '))
self._active_connectors = config
self._gateway.tb_client.client.send_attributes({'active_connectors': config})
def _handle_connector_configuration_update(self, config):

View File

@@ -72,7 +72,11 @@ class TbLogger(logging.Logger):
def _send_errors(self):
is_tb_client = False
while not is_tb_client and not self._gateway.stopped:
while not self._gateway:
sleep(1)
while not is_tb_client:
is_tb_client = hasattr(self._gateway, 'tb_client')
sleep(1)