Index: dialin/hd/valves.py =================================================================== diff -u -re2d925f873714f2bc9a4b90ce7b72fd78919f391 -r3f640809b83e8f5bc080ba3736d6c0719d1503df --- dialin/hd/valves.py (.../valves.py) (revision e2d925f873714f2bc9a4b90ce7b72fd78919f391) +++ dialin/hd/valves.py (.../valves.py) (revision 3f640809b83e8f5bc080ba3736d6c0719d1503df) @@ -15,12 +15,20 @@ VBA = 2 VBV = 3 + @classmethod + def has_value(cls, value): + return value in cls._value2member_map_ + class ValvesPositions(enum.Enum): VALVE_POSITION_NOT_IN_POSITION = 0 VALVE_POSITION_A_INSERT_EJECT = 1 VALVE_POSITION_B_OPEN = 2 VALVE_POSITION_C_CLOSE = 3 + @classmethod + def has_value(cls, value): + return value in cls._value2member_map_ + class ValvesStates(enum.Enum): VALVE_STATE_WAIT_FOR_POST = 0 VALVE_STATE_HOMING_NOT_STARTED = 1 @@ -30,10 +38,18 @@ VALVE_STATE_IN_TRANSITION = 5 VALVE_STATE_IN_BYPASS_MODE = 6 + @classmethod + def has_value(cls, value): + return value in cls._value2member_map_ + class AirTrapState(enum.Enum): STATE_CLOSED = 0 STATE_OPEN = 1 + @classmethod + def has_value(cls, value): + return value in cls._value2member_map_ + class HDValves(_AbstractSubSystem): """ \class HDValves @@ -278,18 +294,14 @@ air_trap = struct.unpack('i', bytearray( message['message'][self.START_AIR_TRAP_VALVE_STATUS:self.END_AIR_TRAP_VALVE_STATUS]))[0] - # To make sure the valve number is not out of range - try: - # Get the valve name + # To make sure values of the enums are not out of range + if ValvesEnum.has_value(vlv_ID) and ValvesPositions.has_value(pos_ID) and ValvesStates.has_value(pos_ID): vlv_name = ValvesEnum(vlv_ID).name # Update the valves dictionary self.valves_status[vlv_name] = {'Valve': vlv_name, 'PosID': ValvesPositions(pos_ID).name, 'PosCnt': pos_cnt, 'Cmd': next_pos, 'State': ValvesStates(state_ID).name, 'Current': current, 'PosA': pos_a, 'PosB': pos_b, 'PosC': pos_c, 'PWM': pwm} - except: - self.logger.debug('Invalid ID Selected') - try: + if AirTrapState.has_value(air_trap): self.hd_air_trap_status = AirTrapState(air_trap).name - except: - self.hd_air_trap_status = 'Valve Status Unknown' +