From 9891e77062850f3f986fbfea68c36a7ef5392fdf Mon Sep 17 00:00:00 2001 From: Alexander Schrode Date: Fri, 20 May 2022 20:07:40 +0200 Subject: [PATCH] Fix enum regression --- asyncua/ua/ua_binary.py | 7 +++---- tests/test_common.py | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/asyncua/ua/ua_binary.py b/asyncua/ua/ua_binary.py index 9724ff2ac..b6eaf2713 100644 --- a/asyncua/ua/ua_binary.py +++ b/asyncua/ua/ua_binary.py @@ -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): diff --git a/tests/test_common.py b/tests/test_common.py index d52649352..ec8e950f1 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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):