From e4f5396fa7da51a9d6cc699c69b4029e40d618c7 Mon Sep 17 00:00:00 2001 From: Joao Mario Lago Date: Mon, 16 Dec 2024 21:26:32 -0300 Subject: [PATCH] backend: modem: lte-base: Add edge cases for SN * As some older LTE-EG25-G modems with firmware from 2019 does not respond the IMEI/SN query, we add a bypass for these values --- backend/modem/adapters/quectel/base.py | 27 ++++++++++++++++++++------ backend/modem/models.py | 6 +++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/backend/modem/adapters/quectel/base.py b/backend/modem/adapters/quectel/base.py index a9041de..2f649d9 100644 --- a/backend/modem/adapters/quectel/base.py +++ b/backend/modem/adapters/quectel/base.py @@ -65,18 +65,33 @@ async def get_mt_info(self, cmd: ATCommander) -> ModemDeviceDetails: # OK response = (await cmd.get_mt_info()).data[0] firmware = (await cmd.get_firmware_version_details()).data[0] - imei = (await cmd.get_imei()).data[0] - serial_number = (await cmd.get_serial_number()).data[0] - imsi = (await cmd.get_international_mobile_subscriber_id()).data[0] + + imei = None + try: + imei = (await cmd.get_imei()).data[0][0] + except Exception: + pass + + serial_number = None + try: + serial_number = (await cmd.get_serial_number()).data[0][0] + except Exception: + pass + + imsi = None + try: + imsi = (await cmd.get_international_mobile_subscriber_id()).data[0][0] + except Exception: + pass return ModemDeviceDetails( device=self.device, id=self.id, manufacturer=response[0], product=response[1], - imei=imei[0], - imsi=imsi[0], - serial_number=serial_number[0], + imei=imei, + imsi=imsi, + serial_number=serial_number, firmware_revision=ModemFirmwareRevision( firmware_revision=firmware[0].replace("VERSION: ", ""), timestamp=firmware[1], diff --git a/backend/modem/models.py b/backend/modem/models.py index bc3d4f9..afe1ba2 100644 --- a/backend/modem/models.py +++ b/backend/modem/models.py @@ -19,10 +19,10 @@ class ModemFirmwareRevision(BaseModel): class ModemDeviceDetails(ModemDevice): - imei: str - serial_number: str - imsi: Optional[str] = None firmware_revision: ModemFirmwareRevision + imei: Optional[str] = None + serial_number: Optional[str] = None + imsi: Optional[str] = None class ModemClockDetails(BaseModel):