Commit b1a80860 authored by Denis Štogl's avatar Denis Štogl

Added support for custom datatypes and removed some trailing spaces

parent 6d2c46e4
......@@ -37,7 +37,7 @@ def create_folder(parent, *args):
or namespace index, name
"""
nodeid, qname = _parse_add_args(*args)
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, ua.ObjectIds.FolderType))
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, ua.ObjectIds.FolderType, ua.NodeClass.Object))
def create_object(parent, *args):
......@@ -63,7 +63,7 @@ def create_object(parent, *args):
raise
except Exception as ex:
raise TypeError("This provided objecttype takes either a index, nodeid or string. Received arguments {} and got exception {}".format(args, ex))
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, objecttype))
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, objecttype, ua.NodeClass.Object))
def create_property(parent, *args):
......@@ -116,19 +116,23 @@ def create_subtype(parent, *args):
arguments are nodeid, browsename
or namespace index, name
"""
nodeid, qname = _parse_add_args(*args)
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, None))
nodeid, qname = _parse_add_args(*args[:2])
if len(args) > 3:
node_class = args[3]
else:
node_class = ua.NodeClass.ObjectType
return node.Node(parent.server, _create_object(parent.server, parent.nodeid, nodeid, qname, None, node_class))
def _create_object(server, parentnodeid, nodeid, qname, objecttype):
def _create_object(server, parentnodeid, nodeid, qname, objecttype, node_class):
addnode = ua.AddNodesItem()
addnode.RequestedNewNodeId = nodeid
addnode.BrowseName = qname
addnode.ParentNodeId = parentnodeid
addnode.NodeClass = node_class
#TODO: maybe move to address_space.py and implement for all node types?
if not objecttype:
addnode.ReferenceTypeId = ua.NodeId(ua.ObjectIds.HasSubtype)
addnode.NodeClass = ua.NodeClass.ObjectType
attrs = ua.ObjectTypeAttributes()
attrs.IsAbstract = True
else:
......@@ -137,7 +141,6 @@ def _create_object(server, parentnodeid, nodeid, qname, objecttype):
else:
addnode.ReferenceTypeId = ua.NodeId(ua.ObjectIds.HasComponent)
addnode.NodeClass = ua.NodeClass.Object
if isinstance(objecttype, int):
addnode.TypeDefinition = ua.NodeId(objecttype)
elif isinstance(objecttype, ua.NodeId):
......
......@@ -71,7 +71,7 @@ class Node(object):
def get_data_type_as_variant_type(self):
"""
get data type of node as VariantType
This only works if node is a variable, otherwise type
This only works if node is a variable, otherwise type
may not be convertible to VariantType
"""
result = self.get_attribute(ua.AttributeIds.DataType)
......@@ -424,7 +424,7 @@ class Node(object):
def read_event_history(self, starttime=None, endtime=None, numvalues=0, evtypes=ua.ObjectIds.BaseEventType):
"""
Read event history of a source node
Read event history of a source node
result code from server is checked and an exception is raised in case of error
If numvalues is > 0 and number of events in period is > numvalues
then result will be truncated
......
......@@ -479,26 +479,26 @@ class CommonTests(object):
self.assertTrue(v in childs)
self.assertTrue(p in childs)
def test_add_node_withtype(self):
def test_add_node_withtype(self):
objects = self.opc.get_objects_node()
f = objects.add_folder(3, 'MyFolder_TypeTest')
o = f.add_object(3, 'MyObject1', ua.ObjectIds.BaseObjectType)
self.assertEqual(o.get_type_definition(), ua.ObjectIds.BaseObjectType)
o = f.add_object(3, 'MyObject2', ua.NodeId(ua.ObjectIds.BaseObjectType, 0) )
o = f.add_object(3, 'MyObject2', ua.NodeId(ua.ObjectIds.BaseObjectType, 0))
self.assertEqual(o.get_type_definition(), ua.ObjectIds.BaseObjectType)
base_otype= self.opc.get_node(ua.ObjectIds.BaseObjectType)
custom_otype = base_otype.add_subtype(2, 'MyFooObjectType')
o = f.add_object(3, 'MyObject3', custom_otype.nodeid )
o = f.add_object(3, 'MyObject3', custom_otype.nodeid)
self.assertEqual(o.get_type_definition(), custom_otype.nodeid.Identifier)
references = o.get_references(refs=ua.ObjectIds.HasTypeDefinition, direction=ua.BrowseDirection.Forward)
self.assertEqual(len(references), 1)
self.assertEqual(len(references), 1)
self.assertEqual(references[0].NodeId, custom_otype.nodeid)
def test_references_for_added_nodes(self):
objects = self.opc.get_objects_node()
o = objects.add_object(3, 'MyObject')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment