Skip to content

Commit

Permalink
Parse string Guid NodeId as UUID (#1141) (#1311)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
gitseitanaka and H.Tanaka authored May 6, 2021
1 parent 8582747 commit 3012acf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/client-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def event_notification(self, event):
# get a specific node knowing its node id
#var = client.get_node(ua.NodeId(1002, 2))
#var = client.get_node("ns=3;i=2002")
#var = client.get_node("ns=2;g=1be5ba38-d004-46bd-aa3a-b5b87940c698")
#print(var)
#var.get_data_value() # get value of node as a DataValue object
#var.get_value() # get value of node as a python builtin
Expand Down
2 changes: 1 addition & 1 deletion opcua/ua/uatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _from_string(string):
identifier = v
elif k == "g":
ntype = NodeIdType.Guid
identifier = v
identifier = uuid.UUID("urn:uuid:{0}".format(v))
elif k == "b":
ntype = NodeIdType.ByteString
identifier = v
Expand Down
8 changes: 8 additions & 0 deletions tests/tests_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,3 +897,11 @@ def test_data_type_to_variant_type(self):
}
for dt, vdt in test_data.items():
self.assertEqual(ua_utils.data_type_to_variant_type(self.opc.get_node(ua.NodeId(dt))), vdt)

def test_guid_node_id(self):
"""
Test that a Node can be instantiated with a GUID string and that the NodeId ca be converted to binary.
"""
node = Node(None, "ns=4;g=35d5f86f-2777-4550-9d48-b098f5ee285c")
binary_node_id = ua.ua_binary.nodeid_to_binary(node.nodeid)
assert type(binary_node_id) is bytes

0 comments on commit 3012acf

Please sign in to comment.