From fe9b6194cb28aac20b31011815e7e82e230d1b29 Mon Sep 17 00:00:00 2001 From: "parker.leblanc" Date: Fri, 15 Sep 2023 15:14:22 -0700 Subject: [PATCH] Add a imei check around modem detection loop --- Hologram/Network/Cellular.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Hologram/Network/Cellular.py b/Hologram/Network/Cellular.py index eab5c8c..b9c1d96 100644 --- a/Hologram/Network/Cellular.py +++ b/Hologram/Network/Cellular.py @@ -231,14 +231,22 @@ def _does_modem_exist_for_handler(modemHandler): @staticmethod def scan_for_all_usable_modems() -> list[Modem]: modems = [] + unique_imeis = set() for (_, modemHandler) in Cellular._modemHandlers.items(): modem_exists = Cellular._does_modem_exist_for_handler(modemHandler) if modem_exists: - test_handler = modemHandler() - usable_ports = test_handler.detect_usable_serial_port(stop_on_first=False) - for port in usable_ports: - modem = modemHandler(device_name=port) - modems.append(modem) + try: + test_handler = modemHandler() + usable_ports = test_handler.detect_usable_serial_port(stop_on_first=False) + for port in usable_ports: + modem = modemHandler(device_name=port) + imei = modem.imei + if imei not in unique_imeis: + unique_imeis.add(imei) + modems.append(modem) + except Exception: + # Any exception already logged up the chain + pass return modems