Index: leahi_dialin/utils/base.py =================================================================== diff -u -rc5bfcf84ed942ca5841bf9de155aa0f495b4d28d -rdefe59974cd16b0f1c825bfc61aae7c3862f812e --- leahi_dialin/utils/base.py (.../base.py) (revision c5bfcf84ed942ca5841bf9de155aa0f495b4d28d) +++ leahi_dialin/utils/base.py (.../base.py) (revision defe59974cd16b0f1c825bfc61aae7c3862f812e) @@ -268,12 +268,37 @@ class DialinEnum(Enum): + _ignore_ = ['_str_list'] + _str_list = {} @classmethod 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 label.lower() in cls._str_list[enum_member.name]: + return enum_member + # Replace _ with ' ' and check the list again + elif label.lower().replace('_', ' ') 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 False + class AlarmEnum(Enum): def __init__(self, *args): cls = self.__class__