Index: dialin/dg/events.py =================================================================== diff -u -rd223289863a5bbb7d9f82cacca2d65b7ac3b2281 -re1a940b7549b37e616b28563e6e7c151a897054c --- dialin/dg/events.py (.../events.py) (revision d223289863a5bbb7d9f82cacca2d65b7ac3b2281) +++ dialin/dg/events.py (.../events.py) (revision e1a940b7549b37e616b28563e6e7c151a897054c) @@ -21,14 +21,15 @@ from ..protocols.CAN import DenaliChannels from ..utils.base import AbstractSubSystem, publish from datetime import datetime -from time import strftime, localtime +from time import localtime class DGEvents(AbstractSubSystem): """ Dialysate Generator (DG) Dialin API sub-class for events related commands. """ UNKNOWN_STATE = "UNKNOWN_PREVIOUS_STATE" + def __init__(self, can_interface, logger: Logger): """ @@ -144,7 +145,7 @@ return list_of_events @publish(["dg_events_timestamp", '_dg_event_dictionary']) - def _handler_events_sync(self, message,timestamp = 0.0): + def _handler_events_sync(self, message, timestamp=0.0): """ Handles published events message @@ -192,7 +193,7 @@ else: # No op mode event has been recieved before the submode event was recieved. Use broadcast messages to # determine current op mode. Previous mode can not be known - last_op_tuple = (strftime('%Y-%m-%d %H:%M:%S.%f', localtime(self.dg_event_op_mode_timestamp)), + last_op_tuple = (localtime(self.dg_event_op_mode_timestamp), DGEventList.DG_EVENT_OP_MODE_CHANGE.name, DGEvents.UNKNOWN_STATE, DGOpModes(self.dg_event_op_mode).name) # Get the current and previous operation modes of the last tuple in the list of the sub modes @@ -232,8 +233,12 @@ # previous and current do not match so in the last type (timestamp, event type, 8, 3) the prev state # should be from op mode 8 and the current state should be from op mode 3 previous_op_mode = last_op_tuple[len(last_op_tuple) - 2] - previous_sub_mode_enum_class = self._dg_op_mode_2_sub_mode[previous_op_mode] - event_data_1 = previous_sub_mode_enum_class(event_data_1).name + if previous_op_mode != DGEvents.UNKNOWN_STATE: + previous_sub_mode_enum_class = self._dg_op_mode_2_sub_mode[previous_op_mode] + event_data_1 = previous_sub_mode_enum_class(event_data_1).name + # Unknown previous state. Display value instead of name. + else: + event_data_1 = str(event_data_1) event_data_2 = current_sub_mode_enum_class(event_data_2).name else: @@ -253,7 +258,7 @@ self._dg_event_dictionary[event_state_name].append(event_tuple) self.dg_events_timestamp = timestamp - @publish(["dg_event_op_mode_timestamp","dg_event_op_mode", "dg_event_sub_mode"]) + @publish(["dg_event_op_mode_timestamp", "dg_event_op_mode", "dg_event_sub_mode"]) def _handler_dg_op_mode_sync(self, message, timestamp=0.0): """ Handles published DG operation mode messages. Current DG operation mode @@ -270,4 +275,4 @@ self.dg_event_op_mode = mode[0] self.dg_event_sub_mode = smode[0] - self.dg_event_op_mode_timestamp = timestamp \ No newline at end of file + self.dg_event_op_mode_timestamp = timestamp Index: dialin/hd/hd_events.py =================================================================== diff -u -rd223289863a5bbb7d9f82cacca2d65b7ac3b2281 -re1a940b7549b37e616b28563e6e7c151a897054c --- dialin/hd/hd_events.py (.../hd_events.py) (revision d223289863a5bbb7d9f82cacca2d65b7ac3b2281) +++ dialin/hd/hd_events.py (.../hd_events.py) (revision e1a940b7549b37e616b28563e6e7c151a897054c) @@ -21,7 +21,7 @@ from ..protocols.CAN import DenaliChannels from ..utils.base import AbstractSubSystem, publish from datetime import datetime -from time import strftime, localtime +from time import localtime class HDEvents(AbstractSubSystem): @@ -189,7 +189,7 @@ else: # No op mode event has been recieved before the submode event was recieved. Use broadcast messages to # determine current op mode. Previous mode can not be known - last_op_tuple = (strftime('%Y-%m-%d %H:%M:%S.%f', localtime(self.hd_event_op_mode_timestamp)), + last_op_tuple = (localtime(self.hd_event_op_mode_timestamp), HDEventList.HD_EVENT_OP_MODE_CHANGE.name, HDEvents.UNKNOWN_STATE, HDOpModes(self.hd_event_op_mode).name) @@ -230,8 +230,12 @@ # previous and current do not match so in the last type (timestamp, event type, 8, 3) the prev state # should be from op mode 8 and the current state should be from op mode 3 previous_op_mode = last_op_tuple[len(last_op_tuple) - 2] - previous_sub_mode_enum_class = self._hd_op_mode_2_sub_mode[previous_op_mode] - event_data_1 = previous_sub_mode_enum_class(event_data_1).name + if previous_op_mode != HDEvents.UNKNOWN_STATE: + previous_sub_mode_enum_class = self._hd_op_mode_2_sub_mode[previous_op_mode] + event_data_1 = previous_sub_mode_enum_class(event_data_1).name + # Unknown previous state. Display value instead of name. + else: + event_data_1 = str(event_data_1) event_data_2 = current_sub_mode_enum_class(event_data_2).name else: @@ -252,7 +256,7 @@ self.hd_event_timestamp = timestamp @publish(["hd_event_op_mode_timestamp", "hd_event_op_mode", "hd_event_sub_mode"]) - def _handler_hd_op_mode_sync(self, message, timestamp = 0.0): + def _handler_hd_op_mode_sync(self, message, timestamp=0.0): """ Handles published HD operation mode messages. Current HD operation mode is captured for reference. @@ -267,4 +271,4 @@ self.hd_event_op_mode = mode[0] self.hd_event_sub_mode = smode[0] - self.hd_event_op_mode_timestamp = timestamp \ No newline at end of file + self.hd_event_op_mode_timestamp = timestamp