From 3f096bda96dbce59870a05925c5210eed01f423d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 27 Mar 2024 17:30:37 +0100 Subject: [PATCH] fixes loading enum from json file Loading from json file happens by name. The sio client will send the whole enumeration and thus we have to handle both strings and enumerations. --- src/pydase/data_service/state_manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pydase/data_service/state_manager.py b/src/pydase/data_service/state_manager.py index 84af429..cba16a1 100644 --- a/src/pydase/data_service/state_manager.py +++ b/src/pydase/data_service/state_manager.py @@ -253,7 +253,9 @@ class StateManager: enum_attr = get_object_attr_from_path_list(target_obj, [attr_name]) # take the value of the existing enum class # TODO: this might break when you set a value from a different enum - setattr(target_obj, attr_name, enum_attr.__class__[value.name]) + if isinstance(value, enum.Enum): + value = value.name + setattr(target_obj, attr_name, enum_attr.__class__[value]) elif attr_cache_type == "list": list_obj = get_object_attr_from_path_list(target_obj, [attr_name]) list_obj[index] = value