Skip to content

Commit 3012acf

Browse files
gitseitanakaH.Tanaka
andauthored
Parse string Guid NodeId as UUID (#1141) (#1311)
* Parse string Guid NodeId as UUID (#1141) The following is the original : FreeOpcUa/opcua-asyncio@0529ec7 * Fixed The Travis CI build failed * Add test The following is the original : FreeOpcUa/opcua-asyncio@0529ec7 Co-authored-by: H.Tanaka <hirokazu.tanaka@users.noreply.github.com>
1 parent 8582747 commit 3012acf

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

examples/client-example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def event_notification(self, event):
5858
# get a specific node knowing its node id
5959
#var = client.get_node(ua.NodeId(1002, 2))
6060
#var = client.get_node("ns=3;i=2002")
61+
#var = client.get_node("ns=2;g=1be5ba38-d004-46bd-aa3a-b5b87940c698")
6162
#print(var)
6263
#var.get_data_value() # get value of node as a DataValue object
6364
#var.get_value() # get value of node as a python builtin

opcua/ua/uatypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def _from_string(string):
362362
identifier = v
363363
elif k == "g":
364364
ntype = NodeIdType.Guid
365-
identifier = v
365+
identifier = uuid.UUID("urn:uuid:{0}".format(v))
366366
elif k == "b":
367367
ntype = NodeIdType.ByteString
368368
identifier = v

tests/tests_common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,3 +897,11 @@ def test_data_type_to_variant_type(self):
897897
}
898898
for dt, vdt in test_data.items():
899899
self.assertEqual(ua_utils.data_type_to_variant_type(self.opc.get_node(ua.NodeId(dt))), vdt)
900+
901+
def test_guid_node_id(self):
902+
"""
903+
Test that a Node can be instantiated with a GUID string and that the NodeId ca be converted to binary.
904+
"""
905+
node = Node(None, "ns=4;g=35d5f86f-2777-4550-9d48-b098f5ee285c")
906+
binary_node_id = ua.ua_binary.nodeid_to_binary(node.nodeid)
907+
assert type(binary_node_id) is bytes

0 commit comments

Comments
 (0)