From ec44657aea4a3d71d51f8dd62935fd8c0af09b2d Mon Sep 17 00:00:00 2001 From: imbeacon Date: Fri, 24 Nov 2023 13:57:37 +0200 Subject: [PATCH] Added handling for empty config --- thingsboard_gateway/gateway/tb_gateway_service.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/thingsboard_gateway/gateway/tb_gateway_service.py b/thingsboard_gateway/gateway/tb_gateway_service.py index fa266b673..aeb0b6288 100644 --- a/thingsboard_gateway/gateway/tb_gateway_service.py +++ b/thingsboard_gateway/gateway/tb_gateway_service.py @@ -519,7 +519,8 @@ def __stop_gateway(self): log.info("The gateway has been stopped.") self.tb_client.disconnect() self.tb_client.stop() - self.manager.shutdown() + if hasattr(self, "manager"): + self.manager.shutdown() def __init_remote_configuration(self, force=False): if (self.__config["thingsboard"].get("remoteConfiguration") or force) and self.__remote_configurator is None: @@ -730,7 +731,7 @@ def _load_connectors(self, config=None): connector.get('class'))) if connector_class is None: - log.warning("Connector implementation not found for %s", connector["name"]) + log.warning("Connector implementation not found for %s", connector['name']) else: self._implemented_connectors[connector['type']] = connector_class elif connector['type'] == "grpc": @@ -757,10 +758,8 @@ def _load_connectors(self, config=None): if connector['type'] != 'grpc' and isinstance(connector_conf, dict): connector_conf["name"] = connector['name'] self.connectors_configs[connector['type']].append({"name": connector['name'], - "config": {connector[ - 'configuration']: connector_conf} if - connector[ - 'type'] != 'grpc' else connector_conf, + "config": {connector['configuration']: connector_conf} if + connector['type'] != 'grpc' else connector_conf, "config_updated": stat(config_file_path), "config_file_path": config_file_path, "grpc_key": connector_persistent_key}) @@ -785,7 +784,7 @@ def __connect_with_connectors(self): connector = None connector_name = None try: - if connector_config["config"][config] is not None: + if connector_config["config"][config] is not None and len(connector_config["config"][config].keys()) > 2: connector_name = connector_config["name"] if not self.available_connectors.get(connector_name): @@ -799,7 +798,7 @@ def __connect_with_connectors(self): else: break else: - log.info("Config not found for %s", connector_type) + log.info("Config not found or empty for %s", connector_type) except Exception as e: log.exception(e, attr_name=connector_name) if connector is not None: