From eb1ec7149926b6ca737dcce232de58c23f523079 Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 18 Oct 2026 05:19:23 -0700 Subject: [PATCH] ble.py - add history try block --- api/ble.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/api/ble.py b/api/ble.py index df44cdd..f141309 100644 --- a/api/ble.py +++ b/api/ble.py @@ -296,23 +296,26 @@ def test(test_count = 0, bt_usb_id = None) -> None: print("Done") prev_list_snapshot = None print("Just before the loop") - while not test_result: - # Check if the failed list has been the same for 5 loops - print("Check if the failed list has been the same for 5 loops") - if prev_list_snapshot is not None and passed_list == prev_list_snapshot: - # List unchanged - add to mac_history - print("List unchanged - add to mac_history") - mac_history.append(passed_list) - else: - # List changed - reset mac_history - print("List changed - reset mac_history") - mac_history = [] - mac_history.append(passed_list) - if len(mac_history) == 5 and all(lst == mac_history[0] for lst in mac_history): - log.warning(f"Last 5 tests have been identical, resetting adapter") - reset_adapter() - mac_history = [] - prev_list_snapshot = current_list + try: + while not test_result: + # Check if the failed list has been the same for 5 loops + print("Check if the failed list has been the same for 5 loops") + if prev_list_snapshot is not None and passed_list == prev_list_snapshot: + # List unchanged - add to mac_history + print("List unchanged - add to mac_history") + mac_history.append(passed_list) + else: + # List changed - reset mac_history + print("List changed - reset mac_history") + mac_history = [] + mac_history.append(passed_list) + if len(mac_history) == 5 and all(lst == mac_history[0] for lst in mac_history): + log.warning(f"Last 5 tests have been identical, resetting adapter") + reset_adapter() + mac_history = [] + prev_list_snapshot = current_list + except Exception as e: + log.error(f"Something went wrong in the history loop - {e}") log.info(f" Test run: {test_count} - loop {test_loop_count} start. Initializing run...") test_run_results = sensor_data_query(test_list)