Skip to content

Commit e4036cd

Browse files
author
Olof Ohlsson Sax
committed
Add support for reading structure with subtyped values
1 parent 772316d commit e4036cd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

asyncua/common/structures104.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def make_structure_code(data_type, struct_name, sdef, log_error=True):
179179
ua.StructureType.Structure,
180180
ua.StructureType.StructureWithOptionalFields,
181181
ua.StructureType.Union,
182+
ua.StructureType.StructureWithSubtypedValues,
182183
):
183184
raise NotImplementedError(
184185
f"Only StructureType implemented, not {ua.StructureType(sdef.StructureType).name} for node {struct_name} with DataTypdeDefinition {sdef}"
@@ -240,8 +241,11 @@ class {struct_name}{base_class}:
240241
elif sfield.ValueRank >= 1 or sfield.ArrayDimensions:
241242
uatype = f"typing.List[{uatype}]"
242243
if sfield.IsOptional:
243-
uatype = f"typing.Optional[{uatype}]"
244-
default_value = "None"
244+
if sdef.StructureType is ua.StructureType.StructureWithSubtypedValues:
245+
uatype = f"typing.Annotated[{uatype}, 'AllowSubtypes']"
246+
else:
247+
uatype = f"typing.Optional[{uatype}]"
248+
default_value = "None"
245249
fields.append((fname, uatype, default_value))
246250
if is_union:
247251
# Generate getter and setter to mimic opc ua union access

0 commit comments

Comments
 (0)