# Subject/Title: Rinseback - SW - 02 - Recirculate - Q&R # # Functionalities: Testing of Rinseback Recirculate # # Steps: # 1 Handle recirculateRequest sent messages messages from UI to FW # 2 Start Leahi application and navigate to Main Treatment screen # 3 Change Treatment sub mode to Recirculation State, Recirculations Sub State to DISCONNECT_PATIENT_STATE # 4 Compare Recirculate Set Up Screen title text, Click on buttons verify FW received, Compare Rejection reason # 5 Compare Recirculate In Progress title text, Click on buttons verify FW received, Compare Rejection reason # 6 Compare Reconnect To Patient title text, Click on buttons verify FW received, Compare Rejection reason import names from configuration import config, utility from leahi_dialin.ui import utils from leahi_dialin.ui.td_messaging import TD_Messaging from leahi_dialin.common.td_defs import TDOpModes, TDTreatmentStates, TDTreaRecircStates from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.utils import conversions td_simulator = TD_Messaging() can_interface = td_simulator.can_interface recirculateRequest = None # handler for messages from UI to FW def handle_recirculate_request(message, timestamp=0.0): """ Called when the user requests to firmware from UI @return: None """ message = message["message"] index = MsgFieldPositions.START_POS_FIELD_1 state, index = conversions.bytearray_to_integer(message, index) global recirculateRequest recirculateRequest = state def verify_screen_header(config_title): """Verifies that the correct screen title is displayed in the header bar.""" headerbar_container = utility.get_object_from_names(names.o_headerBar_HeaderBar) title_obj = utility.findChildByText(headerbar_container, config_title) if title_obj is not None: test.compare( title_obj.text, config_title, f"{config_title} screen is displayed and title text matches.", ) def click_and_verify_fw_request(button_name, expected_value, log_message): """Clicks a button and waits for the firmware to receive the specific request value.""" mouseClick(utility.get_object_from_names(button_name)) test.verify( waitFor(lambda: recirculateRequest == expected_value, 3000), f"Testing FW received {log_message}", ) def verify_recirculation_rejection(): """Comparison of Rejection Reason""" td_simulator.td_recirculate_cmd_response(0, 1) rejectionReason = waitForObject( utility.setObjectText( text=config.REJECTION_REASON, obj=names.o_EndTreatmentBase_NotificationBar_NotificationBarSmall, ) ) test.compare( rejectionReason.text, config.REJECTION_REASON, "Rejection Reason text should be :" + str(rejectionReason.text), ) def verify_recirculation_in_progress_screen_rejection(): """Comparison of Rejection Reason""" td_simulator.td_recirculate_cmd_response(0, 1) rejectionReason = waitForObject( utility.setObjectText( text=config.REJECTION_REASON, obj=names.o_Recirculate_InProgress_Screen_NotificationBar, ) ) test.compare( rejectionReason.text, config.REJECTION_REASON, "Rejection Reason text should be :" + str(rejectionReason.text), ) def verify_reconnect_to_patient_screen_rejection(): """Comparison of Rejection Reason""" td_simulator.td_recirculate_cmd_response(0, 1) rejectionReason = waitForObject( utility.setObjectText( text=config.REJECTION_REASON, obj=names.o_EndTreatmentBase_NotificationBar_NotificationBarSmall_2, ) ) test.compare( rejectionReason.text, config.REJECTION_REASON, "Rejection Reason text should be :" + str(rejectionReason.text), ) def recirculate_set_up_screen(): test.startSection("Verify Recirculate Set Up Screen") td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_RECIRC_STATE.value, 0, 0, 0, 0, 0, TDTreaRecircStates.TREATMENT_RECIRC_DISCONNECT_PATIENT_STATE.value, 0, 0, 0, ) verify_screen_header(config.RECIRCULATE_SET_UP) click_and_verify_fw_request( names.o_EndTreatmentBase_ButtonEndTreatment, 3, "End Treatment Button Value" ) verify_recirculation_rejection() click_and_verify_fw_request( names.o_EndTreatmentBase_ButtonStartRecirculate, 4, "Start Recirculation Button Value", ) verify_recirculation_rejection() test.endSection() def recirculate_in_progress_screen(): test.startSection("Verify Recirculate In Progress Screen") td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_RECIRC_STATE.value, 0, 0, 0, 0, 0, TDTreaRecircStates.TREATMENT_RECIRC_RECIRC_STATE.value, 0, 0, 0, ) verify_screen_header(config.RECIRCULATE_IN_PROGRESS) td_simulator.td_recirculate_progress(300, 270) recirculation_desc = utility.get_object_from_names( names.o_EndTreatmentBase_label_Text ) test.compare( recirculation_desc.text, config.RECIRCULATION_COUNTDOWN_DESCRIPTION_TEXT, "Recirculation Countdown Description Text", ) test.compare( utility.get_object_from_names( names.o_EndTreatmentBase_TimeText_minute_Text ).text, "04", "Recirculation Countdown Minutes", ) test.compare( utility.get_object_from_names( names.o_EndTreatmentBase_TimeText_second_Text ).text, "30", "Recirculation Countdown Seconds", ) click_and_verify_fw_request( names.o_Recirculate_InProgress_Screen_ButtonEndTreatment, 3, "End Treatment Button Value", ) verify_recirculation_in_progress_screen_rejection() click_and_verify_fw_request( names.o_EndTreatmentBase_ButtonResume, 0, "Resume Button Value" ) verify_recirculation_in_progress_screen_rejection() test.endSection() def reconnect_to_patient_screen(): test.startSection("Verify Reconnect To Patient Screen") td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_RECIRC_STATE.value, 0, 0, 0, 0, 0, TDTreaRecircStates.TREATMENT_RECIRC_RECONNECT_PATIENT_STATE.value, 0, 0, 0, ) verify_screen_header(config.RECONNECT_TO_PATIENT) click_and_verify_fw_request( names.o_EndTreatmentBase_ButtonEndTreatment_2, 3, "End Treatment Button Value" ) verify_reconnect_to_patient_screen_rejection() click_and_verify_fw_request( names.o_EndTreatmentBase_ButtonResume_2, 1, "Start Resume Treatment Button Value", ) verify_reconnect_to_patient_screen_rejection() test.endSection() def main(): utils.tstStart(__file__) if can_interface is None: test.fail("CAN Interface is not available. Stopping tests.") return channel_id = CAN.DenaliChannels.ui_to_td_ch_id # Register Recirculate Request message_id = MsgIds.MSG_ID_UI_RECIRCULATE_REQUEST.value can_interface.register_receiving_publication_function( channel_id, message_id, handle_recirculate_request ) startApplication(utility.aut("-q")) td_simulator.td_operation_mode(TDOpModes.MODE_TREA.value, 0) td_simulator.td_tx_state( TDTreatmentStates.TREATMENT_DIALYSIS_STATE.value, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) recirculate_set_up_screen() recirculate_in_progress_screen() reconnect_to_patient_screen() utils.tstDone()