def convert(self, config, data):
     device_name = self.__config["deviceName"]
     result = {
         "deviceName": device_name,
         "deviceType": self.__config.get("deviceType", "OPC-UA Device"),
         "attributes": [],
         "telemetry": [],
     }
     current_variable = config.split('.')
     try:
         for attr in self.__config["attributes"]:
             path = TBUtility.get_value(attr["path"], get_tag=True)
             if path == '.'.join(current_variable[-len(path.split('.')):]):
                 result["attributes"].append({
                     attr["key"]:
                     attr["path"].replace("${" + path + "}", str(data))
                 })
         for ts in self.__config["timeseries"]:
             path = TBUtility.get_value(ts["path"], get_tag=True)
             if path == '.'.join(current_variable[-len(path.split('.')):]):
                 result["telemetry"].append({
                     ts["key"]:
                     ts["path"].replace("${" + path + "}", str(data))
                 })
         return result
     except Exception as e:
         log.exception(e)
Ejemplo n.º 2
0
 def convert(self, config, data):
     device_name = self.__config["deviceName"]
     result = {
         "deviceName": device_name,
         "deviceType": self.__config.get("deviceType", "OPC-UA Device"),
         "attributes": [],
         "telemetry": [],
     }
     try:
         information_types = {
             "attributes": "attributes",
             "timeseries": "telemetry"
         }
         for information_type in information_types:
             for information in self.__config[information_type]:
                 path = TBUtility.get_value(information["path"],
                                            get_tag=True)
                 if isinstance(config, tuple):
                     config_information = config[0].replace('\\\\', '\\') if path == config[0].replace('\\\\', '\\') or fullmatch(path,
                                                                                                                                  config[0].replace('\\\\',
                                                                                                                                                    '\\')) else \
                     config[1].replace('\\\\', '\\')
                 else:
                     config_information = config.replace('\\\\', '\\')
                 if path == config_information or fullmatch(
                         path, config_information) or path.replace(
                             '\\\\', '\\') == config_information:
                     result[information_types[information_type]].append({
                         information["key"]:
                         information["path"].replace(
                             "${" + path + "}", str(data))
                     })
         return result
     except Exception as e:
         log.exception(e)