Index: leahi_dialin/fp/modules/valves.py =================================================================== diff -u -ra4ec379f84f2a737f2f5c16fb925f1371c9fd55a -r9eeeeb3a8bc94c59e506254b088493fd69c3b1e1 --- leahi_dialin/fp/modules/valves.py (.../valves.py) (revision a4ec379f84f2a737f2f5c16fb925f1371c9fd55a) +++ leahi_dialin/fp/modules/valves.py (.../valves.py) (revision 9eeeeb3a8bc94c59e506254b088493fd69c3b1e1) @@ -92,6 +92,36 @@ self.p6_valv.get("state") ] + @staticmethod + def sort_by_id(observation): + """ + Converts a published dictionary of valve state information to an ordered list + of tuples. + + @param observation: dictionary of the observed valve states + @return: a list of tuples of the valve states + """ + + result = [] + for key, value in observation.items(): + if isinstance(value, dict): + result.append((key, value.get("id", None), value.get("state", None))) + + result = sorted(result, key=lambda each: each[1]) + return result + + @staticmethod + def _binary_to_valve_state(binary) -> bool: + """ + @param binary: binary value + @return: 1 = energized, otherwise de-energized + """ + + if binary != 0: + return ENERGIZED + else: + return DEENERGIZED + @publish([ "msg_id_fp_valves_states_data", "valve_states_all", @@ -113,6 +143,7 @@ @param message: published FP valves states message @return: none """ + vst = struct.unpack('H', bytearray(message['message'][self.START_POS_VALVES_STATES:self.END_POS_VALVES_STATES])) self.valve_states_all = vst[0] # Extract each valve state from U16 valves states using bit-masking @@ -135,36 +166,6 @@ self.fp_valves_states_timestamp = timestamp - @staticmethod - def sort_by_id(observation): - """ - Converts a published dictionary of valve state information to an ordered list - of tuples. - - @param observation: dictionary of the observed valve states - @return: a list of tuples of the valve states - """ - - result = [] - for key, value in observation.items(): - if isinstance(value, dict): - result.append((key, value.get("id", None), value.get("state", None))) - - result = sorted(result, key=lambda each: each[1]) - return result - - @staticmethod - def _binary_to_valve_state(binary) -> bool: - """ - @param binary: binary value - @return: 1 = energized, otherwise de-energized - """ - - if binary != 0: - return ENERGIZED - else: - return DEENERGIZED - def cmd_valve_sensed_state_override(self, valve: int, state: bool, reset: int = NO_RESET) -> int: """ Constructs and sends the valve sensed state override command. @@ -208,7 +209,7 @@ Given valve ID must be one of the valve IDs listed below. @param valve: unsigned int - valve ID - @param state: int - valve state + @param state: int - valve state (0=de-energized/closed, 1=energized/open) @param reset: integer - 1 to reset a previous override, 0 to override @return: 1 if successful, zero otherwise """