From b5469626584705bfce9c741a056a9892986f31f2 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Fri, 17 Sep 2021 14:20:19 +0200
Subject: [PATCH] L2SS-343: Remove hack if namespace doesn't exist (because it
 does now in our servers), and prepend the namespace index for any path
 element that does not have it explicitly set.

---
 devices/clients/opcua_client.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/devices/clients/opcua_client.py b/devices/clients/opcua_client.py
index 8a986a0c7..68ed86283 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:
-- 
GitLab