diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py index 8a986a0c7f98819ecad9ea6a5710aaca19c1ac0c..68ed862839c0841e80632fa758a472d9f841b0d0 100644 --- a/devices/clients/opcua_client.py +++ b/devices/clients/opcua_client.py @@ -52,16 +52,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: - #TODO remove once SDP is fixed - self.streams.warn_stream("Cannot determine the OPC-UA name space index. Will try and use the default = 2.") - self.name_space_index = 2 + 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() @@ -136,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: