From dfb39e07efab52c63322f2cf062bba401a47a74a Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 4 May 2025 18:23:38 -0400 Subject: [PATCH] warn: add warning if selected pump serial has no recent events --- tconnectsync/sync/tandemsource/choose_device.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tconnectsync/sync/tandemsource/choose_device.py b/tconnectsync/sync/tandemsource/choose_device.py index 1c72324..cfdda9c 100644 --- a/tconnectsync/sync/tandemsource/choose_device.py +++ b/tconnectsync/sync/tandemsource/choose_device.py @@ -24,6 +24,20 @@ class ChooseDevice: tconnectDevice = serialNumberToPump[str(self.secret.PUMP_SERIAL_NUMBER)] + # Warn if pump is stale (no events in >3 days) + try: + max_event_date = arrow.get(tconnectDevice["maxDateWithEvents"]) + age_days = (arrow.utcnow() - max_event_date).days + + if age_days > 3: + logger.warning( + f"The selected pump (serial {tconnectDevice['serialNumber']}) has no events in the last {age_days} days " + f"(last seen: {tconnectDevice['maxDateWithEvents']}). " + "You may have switched to a new pump. Consider removing or updating PUMP_SERIAL_NUMBER in your config." + ) + except Exception as e: + logger.debug(f"Could not parse maxDateWithEvents to check for staleness: {e}") + logger.info(f'Using pump with serial: {tconnectDevice["serialNumber"]} (tconnectDeviceId: {tconnectDevice["tconnectDeviceId"]}, last seen: {tconnectDevice["maxDateWithEvents"]})') else: maxDateSeen = None