Index: tests/test_hd_simulator.py =================================================================== diff -u -ra08848ed6275cf2afa3bfb7f3c87709b69c224bc -rf3171e14b9cbfabe015e6aa093234d8dd8b55b45 --- tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision a08848ed6275cf2afa3bfb7f3c87709b69c224bc) +++ tests/test_hd_simulator.py (.../test_hd_simulator.py) (revision f3171e14b9cbfabe015e6aa093234d8dd8b55b45) @@ -18,6 +18,8 @@ sys.path.append("..") from dialin.ui.hd_simulator import HDSimulator, MsgDefs, Alarms +from dialin.hd.hemodialysis_device import HD +from dialin.utils.base import AbstractObserver from time import sleep @@ -47,23 +49,45 @@ hd_simulator.cmd_send_treatment_parameter_validation_response(rejections) +class Observer(AbstractObserver): + def __init__(self): + self.timeout_expired = False + + def update(self, result): + print(result) + self.timeout_expired = result.get("poweroff_timeout_expired", False) + + def test_poweroff(): + hd = HD() + + observer = Observer() + hd.buttons.attach(observer) + hd_simulator = HDSimulator(log_level="DEBUG") hd_simulator.cmd_send_poweroff_button_pressed() - hd_simulator.cmd_send_broadcast_poweroff() + sleep(1) + hd_simulator.cmd_send_poweroff_timeout() + sleep(1) + hd_simulator.cmd_send_broadcast_poweroff_imminent() + while not observer.timeout_expired: + sleep(1) + def test_clear_alarms(): hd_simulator = HDSimulator() - hd_simulator.cmd_activate_alarm(Alarms.ALARM_ID_ARTERIAL_PRESSURE_HIGH) + hd_simulator.cmd_activate_alarm(Alarms.ALARM_ID_TREATMENT_STOPPED_BY_USER) sleep(1) hd_simulator.cmd_send_clear_alarms() if __name__ == '__main__': - # test_invalid_parameters() test_clear_alarms() + sleep(1) + test_poweroff() +