Compare commits

...
3 Commits
Author SHA1 Message Date
James Woglom a5cbc5d612 v2.0.3 2024-10-01 16:08:06 -04:00
James Woglom ef515021cc check changes for last seen event id 2024-10-01 16:07:48 -04:00
James Woglom 4af54bf7cb set tzinfo (fix #100) 2024-10-01 15:59:20 -04:00
5 changed files with 28 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[metadata]
name = tconnectsync
version = 2.0.2
version = 2.0.3
author = James Woglom
author_email = j@wogloms.net
description = Syncs Tandem t:connect pump data to Nightscout for the t:slim X2
+7 -2
View File
@@ -111,9 +111,14 @@ def main(*args, **kwargs):
if args.auto_update:
u = TandemSourceAutoupdate(secret)
sys.exit(u.process(tconnect, nightscout, time_start, time_end, args.pretend, features=args.features))
changed, last_event_id = u.process(tconnect, nightscout, time_start, time_end, args.pretend, features=args.features)
# return exit code 0 if processed events
sys.exit(0 if changed>0 else 1)
else:
tconnectDevice = TandemSourceChooseDevice(secret, tconnect).choose()
added = TandemSourceProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend=args.pretend, features=args.features).process(time_start, time_end)
sys.exit(added)
# return exit code 0 if processed events
sys.exit(0 if added>0 else 1)
+8 -2
View File
@@ -1,6 +1,8 @@
import struct
import arrow
from ..secret import TIMEZONE_NAME
from dataclasses import dataclass
EVENT_LEN = 26
@@ -29,7 +31,11 @@ class RawEvent:
seqNum = seqNum,
raw = raw
)
@property
def timestamp(self):
return arrow.get(TANDEM_EPOCH + self.timestampRaw)
# Event timestamps do not have TZ data attached to them when parsed,
# but represent the user's time zone setting. So we keep the time
# referenced on them, but force the timezone to what the user
# requests via the TZ secret.
return arrow.get(TANDEM_EPOCH + self.timestampRaw, tzinfo=TIMEZONE_NAME)
+6 -2
View File
@@ -18,6 +18,7 @@ class TandemSourceAutoupdate:
self.last_max_date_with_events = None
self.last_event_time = 0
self.last_attempt_time = 0
self.last_event_index = None
self.time_diffs_between_attempts = []
self.time_diffs_between_updates = []
@@ -41,6 +42,7 @@ class TandemSourceAutoupdate:
tconnectDevice = ChooseDevice(self.secret, tconnect).choose()
event_id = None
cur_max_date_with_events = arrow.get(tconnectDevice['maxDateWithEvents'])
if not self.last_max_date_with_events or cur_max_date_with_events > self.cur_max_date_with_events:
logger.info('New reported tandemsource data. (cur_max_date: %s last_max_date: %s)' % (cur_max_date_with_events, self.last_max_date_with_events))
@@ -48,7 +50,7 @@ class TandemSourceAutoupdate:
if pretend:
logger.info('Would update now if not in pretend mode')
else:
added = ProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend, features=features).process(time_start, time_end)
added, event_id = ProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend, features=features).process(time_start, time_end)
logger.info('Added %d items from ProcessTimeRange' % added)
# Track the time it took to find a new event between runs,
@@ -59,8 +61,10 @@ class TandemSourceAutoupdate:
logger.debug('Updating tracking of time since last update: %s' % self.time_diffs_between_updates)
# Mark the last event index uploaded from the pump and timestamp
if event_id:
self.last_event_index = event_id
self.last_event_time = now
self.last_max_date_with_events = cur_max_date_with_events
self.last_event_time = now
self.last_attempt_time = now
self.time_diffs_between_attempts = []
else:
+6 -2
View File
@@ -55,14 +55,18 @@ class ProcessTimeRange:
events_first_time = None
events_last_time = None
last_event_id = None # aka seqnum
for_eventclass = collections.defaultdict(list)
for event in events:
if not events_first_time:
events_first_time = event.eventTimestamp
if not events_last_time:
events_last_time = event.eventTimestamp
if not last_event_id:
last_event_id = event.eventId
events_first_time = min(events_first_time, event.eventTimestamp)
events_last_time = max(events_last_time, event.eventTimestamp)
last_event_id = max(event.eventId, last_event_id)
clazz = EventClass.for_event(event)
if clazz:
@@ -91,6 +95,6 @@ class ProcessTimeRange:
else:
logger.info("Skipping %s, is not enabled from features %s" % (updater_class.__name__, self.features))
logger.info("Processed %d events" % processed_count)
return processed_count
logger.info("Processed %d events. Last event ID seen: %d" % (processed_count, last_event_id))
return processed_count, last_event_id