Skip to content

Commit

Permalink
Fix enum regression
Browse files Browse the repository at this point in the history
  • Loading branch information
schroeder- authored and oroulet committed May 21, 2022
1 parent 34e5aab commit 9891e77
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions asyncua/ua/ua_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,9 @@ def create_enum_deserializer(uatype):
typename = 'UInt32'
if hasattr(uatype, 'datatype'):
typename = uatype.datatype()
return getattr(Primitives, typename).unpack
elif isinstance(uatype, Enum):
return lambda val: Primitives.Int32.unpack(val.value)
return Primitives.Int32.unpack
unpack = getattr(Primitives, typename).unpack
return lambda val: uatype(unpack(val))
return lambda val: uatype(Primitives.Int32.unpack(val))


def from_binary(uatype, data):
Expand Down
1 change: 1 addition & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ async def test_custom_struct_with_enum(opc):
var = await opc.opc.nodes.objects.add_variable(idx, "my_struct2", ua.Variant(mystruct, ua.VariantType.ExtensionObject))
val = await var.read_value()
assert val.MyEnum == ua.MyCustEnum2.tutu
assert isinstance(val.MyEnum, ua.MyCustEnum2)


async def test_nested_struct_arrays(opc):
Expand Down

0 comments on commit 9891e77

Please sign in to comment.