########################################################################### # # Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file dialin_enum.py # # @author (last) Zoltan Miskolci # @date (last) 04-May-2026 # @author (original) Zoltan Miskolci # @date (original) 04-May-2026 # ############################################################################ # Module imports from enum import Enum class DialinEnum(Enum): @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 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