Index: leahi_dialin/utils/base.py =================================================================== diff -u -rc5bfcf84ed942ca5841bf9de155aa0f495b4d28d -r41de945f9c773e54e965e80d9e46def828beb732 --- leahi_dialin/utils/base.py (.../base.py) (revision c5bfcf84ed942ca5841bf9de155aa0f495b4d28d) +++ leahi_dialin/utils/base.py (.../base.py) (revision 41de945f9c773e54e965e80d9e46def828beb732) @@ -273,7 +273,33 @@ def has_value(cls, value): return value in cls._value2member_map_ + @classmethod + def from_str(cls, label: str): + for enum_member in cls.__members__.values(): + # If the string matching with the enum's name + if label.lower() == enum_member.name.lower(): + return enum_member + # Replace _ with ' ' and check again + elif label.lower().replace('_', ' ') == enum_member.name.lower().replace('_', ' '): + return enum_member + # If the string matching with the enum's state without the 'mode_' text + elif label.lower() == enum_member.name.lower().replace('mode_', ''): + return enum_member + # If it's in the string list provided for the enum + elif enum_member.name in cls._str_list and label.lower() in cls._str_list[enum_member.name]: + return enum_member + # Replace _ with ' ' and check the list again + elif enum_member.name in cls._str_list and label.lower().replace('_', ' ') in cls._str_list[enum_member.name]: + return enum_member + # Replace _ with ' ' and check the list again with _ with ' ' + elif enum_member.name in cls._str_list and label.lower().replace('_', ' ') in [enum_mem.lower().replace('_', ' ') for enum_mem in cls._str_list[enum_member.name] ]: + return enum_member + # If the enum is the NUM_ collector, then return stop as after that only aliases are present + elif enum_member.name.lower().startswith('num_'): + return None + return None + class AlarmEnum(Enum): def __init__(self, *args): cls = self.__class__