diff --git a/thingsboard_gateway/gateway/tb_gateway_service.py b/thingsboard_gateway/gateway/tb_gateway_service.py index b1dc3e16..3cbf76e9 100644 --- a/thingsboard_gateway/gateway/tb_gateway_service.py +++ b/thingsboard_gateway/gateway/tb_gateway_service.py @@ -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: diff --git a/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py b/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py index 9fa67fc0..2fb2cc9c 100644 --- a/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py +++ b/thingsboard_gateway/tb_utility/tb_gateway_remote_configurator.py @@ -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): diff --git a/thingsboard_gateway/tb_utility/tb_logger.py b/thingsboard_gateway/tb_utility/tb_logger.py index 11d8cc76..58f6f9f9 100644 --- a/thingsboard_gateway/tb_utility/tb_logger.py +++ b/thingsboard_gateway/tb_utility/tb_logger.py @@ -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)