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

Fixed path resolving for Modbus Compability Adapter

This commit is contained in:
samson0v
2022-01-25 14:36:14 +02:00
parent 9fe55df2e4
commit e6c007fe7e
3 changed files with 10 additions and 9 deletions

View File

@@ -11,8 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from os import path
from os.path import exists
from simplejson import dumps
@@ -22,13 +20,11 @@ from thingsboard_gateway.connectors.connector import log
class BackwardCompatibilityAdapter:
config_files_count = 1
CONFIG_PATH = None
if exists('config/'):
CONFIG_PATH = 'config/'
elif exists("/etc/thingsboard-gateway/config/".replace('/', path.sep)):
CONFIG_PATH = "/etc/thingsboard-gateway/config/".replace('/', path.sep)
def __init__(self, config):
def __init__(self, config, config_dir):
self.__config = config
self.__config_dir = config_dir
BackwardCompatibilityAdapter.CONFIG_PATH = self.__config_dir
self.__keys = ['host', 'port', 'type', 'method', 'timeout', 'byteOrder', 'wordOrder', 'retries', 'retryOnEmpty',
'retryOnInvalid', 'baudrate']
@@ -46,7 +42,8 @@ class BackwardCompatibilityAdapter:
log.warning(
'You are using old configuration structure for Modbus connector. It will be DEPRECATED in the future '
'version! New config file "modbus_new.json" was generated in config/ folder. Please, use it.')
'version! New config file "modbus_new.json" was generated in %s folder. Please, use it.', self.CONFIG_PATH)
log.warning('You have to manually connect the new generated config file to tb_gateway.yaml!')
slaves = []
for device in self.__config['server'].get('devices', []):

View File

@@ -94,7 +94,7 @@ class ModbusConnector(Connector, Thread):
self.__gateway = gateway
self._connector_type = connector_type
self.__backward_compatibility_adapter = BackwardCompatibilityAdapter(config)
self.__backward_compatibility_adapter = BackwardCompatibilityAdapter(config, gateway.config_dir)
self.__config = self.__backward_compatibility_adapter.convert()
self.setName(self.__config.get("name", 'Modbus Default ' + ''.join(choice(ascii_lowercase) for _ in range(5))))

View File

@@ -263,6 +263,10 @@ class TBGatewayService:
log.info("The gateway has been stopped.")
self.tb_client.stop()
@property
def config_dir(self):
return self._config_dir
def __close_connectors(self):
for current_connector in self.available_connectors:
try: