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

Fixed check for remote configuration

This commit is contained in:
imbeacon
2024-02-12 10:21:19 +02:00
parent c844839afa
commit bda8f12840
2 changed files with 17 additions and 12 deletions

View File

@@ -554,7 +554,10 @@ class TBGatewayService:
self.manager.shutdown()
def __init_remote_configuration(self, force=False):
if (self.__config["thingsboard"].get("remoteConfiguration") or force) and self.__remote_configurator is None:
remote_configuration_enabled = self.__config["thingsboard"].get("remoteConfiguration")
if not remote_configuration_enabled and force:
log.info("Remote configuration is enabled forcibly!")
if (remote_configuration_enabled or force) and self.__remote_configurator is None:
try:
self.__remote_configurator = RemoteConfigurator(self, self.__config)
if self.tb_client.is_connected() and not self.tb_client.client.get_subscriptions_in_progress():
@@ -688,8 +691,8 @@ class TBGatewayService:
self.tb_client.client.request_attributes(callback=self._attributes_parse)
def __register_connector(self, session_id, connector_key):
if self.__grpc_connectors.get(connector_key) is not None and self.__grpc_connectors[connector_key][
'id'] not in self.available_connectors_by_id:
if (self.__grpc_connectors.get(connector_key) is not None
and self.__grpc_connectors[connector_key]['id'] not in self.available_connectors_by_id):
target_connector = self.__grpc_connectors.get(connector_key)
connector = GrpcConnector(self, target_connector['config'], self.__grpc_manager, session_id)
connector.setName(target_connector['name'])
@@ -830,7 +833,6 @@ class TBGatewayService:
else:
log.warning("Connectors - not found!")
self.__init_remote_configuration(force=True)
log.info("Remote configuration is enabled forcibly!")
def connect_with_connectors(self):
self.__connect_with_connectors()
@@ -849,10 +851,8 @@ class TBGatewayService:
try:
if connector_config["config"][config] is not None:
if ("logLevel" in connector_config["config"][config]
and "name" in connector_config["config"][config]
and len(connector_config["config"][config].keys()) > 3) or \
("logLevel" not in connector_config["config"][config]
and "name" not in connector_config["config"][config]
and len(connector_config["config"][config].keys()) >= 1):
connector_name = connector_config["name"]
connector_id = connector_config["id"]
@@ -861,9 +861,7 @@ class TBGatewayService:
if available_connector is None or available_connector.is_stopped():
connector = self._implemented_connectors[connector_type](self,
connector_config[
"config"][
config],
connector_config["config"][config],
connector_type)
connector.setName(connector_name)
self.available_connectors_by_id[connector_id] = connector

View File

@@ -541,11 +541,18 @@ class RemoteConfigurator:
connector_configuration = found_connector
if connector_configuration.get('id') in self._gateway.available_connectors_by_id:
self._gateway.available_connectors_by_id[connector_configuration['id']].close()
elif connector_configuration.get('name') in self._gateway.available_connectors_by_name:
self._gateway.available_connectors_by_name[connector_configuration['name']].close()
else:
LOG.warning('Connector with id %s not found in available connectors', connector_configuration['id'])
self._gateway.available_connectors_by_id.pop(connector_configuration['id'])
if self._gateway.available_connectors_by_name.get(connector_configuration['name']):
LOG.warning('Connector with id %s not found in available connectors', connector_configuration.get('id'))
if connector_configuration.get('id') in self._gateway.available_connectors_by_id:
self._gateway.available_connectors_by_id.pop(connector_configuration['id'])
connector_configuration['id'] = connector_id
elif connector_configuration.get('name') in self._gateway.available_connectors_by_name:
self._gateway.available_connectors_by_name.pop(connector_configuration['name'])
connector_configuration['id'] = connector_id
else:
LOG.warning('Connector with id %s not found in available connectors', connector_configuration.get('id'))
self._gateway.load_connectors(self._get_general_config_in_local_format())
self._gateway.connect_with_connectors()