diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py index 41d6d0e740de5bc0aabfb7a39b8afd4be6309483..7d915cbd00aee72da2a13b7bbb7365306457cf4d 100644 --- a/devices/clients/opcua_client.py +++ b/devices/clients/opcua_client.py @@ -51,15 +51,12 @@ class OPCUAConnection(CommClient): # determine namespace used - try: - if type(namespace) is str: - self.name_space_index = self.client.get_namespace_index(namespace) - elif type(namespace) is int: - self.name_space_index = namespace - - except Exception as e: - self.streams.error_stream("Could not determine namespace index from namespace: %s: %s", namespace, e) - raise Exception("Could not determine namespace index from namespace %s", namespace) from e + if type(namespace) is str: + self.name_space_index = self.client.get_namespace_index(namespace) + elif type(namespace) is int: + self.name_space_index = namespace + else: + raise TypeError(f"namespace must be of type str or int, but is of type {type(namespace).__name__}") self.obj = self.client.get_objects_node() self.check_nodes() @@ -135,6 +132,9 @@ class OPCUAConnection(CommClient): else: raise Exception("OPC-ua mapping requires either a list of the path or dict with the path. Was given %s type containing: %s", type(annotation), annotation) + # prepend namespace index for each element if none is given + path = [name if ':' in name else f'{self.name_space_index}:{name}' for name in path] + try: node = self.obj.get_child(path) except Exception as e: