Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix in _create_custom_type #722

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions asyncua/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ async def create_custom_object_type(self,
properties=None,
variables=None,
methods=None) -> Coroutine:
"""
properties: [iterable(<name>, <ua.Variant>, <datatype>), ...]
variables: [iterable(<name>, <ua.Variant>, <datatype>), ...]
"""
Copy link
Member

@oroulet oroulet Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not even knew these arguments existed. Why can't we add variable and properties in a new call by adding children to the created type node? That is much more flexible and does not take much longer to type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont know! stumbled over it and realised that it does not work that well ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better flag is as depcrecated then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the delay!
flagging it as depricated will not solve the issue... if you use it you can create a type but it has no modelling rules so our instantiate method will just instantiate the objectnode!
the only thing i added is that i like to pass a list of iterable(name, Variant, Datatype) so the default value for that type can be added via the Variant!
in my opinion a nice feature and i would like to keep it ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but add a small test to make sure it works. Add something in test_common..py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure! need to make some changes on the existing tests aswell as some for that specific case!

if properties is None:
properties = []
if variables is None:
Expand Down Expand Up @@ -565,14 +569,16 @@ async def _create_custom_type(self, idx, name, basetype, properties, variables,
datatype = None
if len(prop) > 2:
datatype = prop[2]
await custom_t.add_property(
idx, prop[0], ua.get_default_value(prop[1]), varianttype=prop[1], datatype=datatype)
prop_node = await custom_t.add_property(
idx, prop[0], prop[1].Value, varianttype=prop[1].VariantType, datatype=datatype)
await prop_node.set_modelling_rule(True)
for variable in variables:
datatype = None
if len(variable) > 2:
datatype = variable[2]
await custom_t.add_variable(
idx, variable[0], ua.get_default_value(variable[1]), varianttype=variable[1], datatype=datatype)
var_node = await custom_t.add_variable(
idx, variable[0], variable[1].Value, varianttype=variable[1].VariantType, datatype=datatype)
await var_node.set_modelling_rule(True)
for method in methods:
await custom_t.add_method(idx, method[0], method[1], method[2], method[3])
return custom_t
Expand Down