Commit 8d583b42 authored by Andreas Heine's avatar Andreas Heine Committed by GitHub

added instantiate_optional support on create object method and possible fix for #307 (#323)

* added instantiate_optional

* Update uatypes.py

* Revert "Update uatypes.py"

This reverts commit 8e9f907a.

* Update uatypes.py

* Revert "Update uatypes.py"

This reverts commit f073371a.

* Update uatypes.py
parent 129344e7
......@@ -50,7 +50,7 @@ async def create_folder(parent, nodeid, bname):
)
async def create_object(parent, nodeid, bname, objecttype=None):
async def create_object(parent, nodeid, bname, objecttype=None, instantiate_optional=True):
"""
create a child node object
arguments are nodeid, browsename, [objecttype]
......@@ -61,7 +61,7 @@ async def create_object(parent, nodeid, bname, objecttype=None):
if objecttype is not None:
objecttype = make_node(parent.server, objecttype)
dname = ua.LocalizedText(qname.Name)
nodes = await instantiate(parent, objecttype, nodeid, bname=qname, dname=dname)
nodes = await instantiate(parent, objecttype, nodeid, bname=qname, dname=dname, instantiate_optional=instantiate_optional)
return nodes[0]
else:
return make_node(
......
......@@ -684,8 +684,8 @@ class Node:
async def add_folder(self, nodeid, bname):
return await create_folder(self, nodeid, bname)
async def add_object(self, nodeid, bname, objecttype=None):
return await create_object(self, nodeid, bname, objecttype)
async def add_object(self, nodeid, bname, objecttype=None, instantiate_optional=True):
return await create_object(self, nodeid, bname, objecttype, instantiate_optional)
async def add_variable(self, nodeid, bname, val, varianttype=None, datatype=None):
return await create_variable(self, nodeid, bname, val, varianttype, datatype)
......
......@@ -750,7 +750,10 @@ class Variant(FrozenClass):
if self.VariantType is None:
self.VariantType = self._guess_type(self.Value)
if self.Value is None and not self.is_array and self.VariantType not in (VariantType.Null, VariantType.String, VariantType.DateTime, VariantType.ExtensionObject):
raise UaError(f"Non array Variant of type {self.VariantType} cannot have value None")
if self.Value == None and self.VariantType == VariantType.NodeId:
self.Value = NodeId(0,0)
else:
raise UaError(f"Non array Variant of type {self.VariantType} cannot have value None")
if self.Dimensions is None and isinstance(self.Value, (list, tuple)):
dims = get_shape(self.Value)
if len(dims) > 1:
......
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