mirror of
https://github.com/bckelley/tconnectsync.git
synced 2026-08-24 03:34:12 -05:00
add unit test
This commit is contained in:
@@ -4495,7 +4495,7 @@ class LidDailyBasal(BaseEvent):
|
||||
|
||||
@property
|
||||
def batteryChargePercent(self):
|
||||
return (256*(self.batteryChargePercentMSBRaw%2)+self.batteryChargePercentLSBRaw)/512
|
||||
return (256*(self.batterychargepercentmsbRaw%2)+self.batterychargepercentlsbRaw)/512
|
||||
|
||||
@staticmethod
|
||||
def build(raw):
|
||||
|
||||
@@ -10,6 +10,7 @@ PUMP_EVENTS = "PUMP_EVENTS"
|
||||
PUMP_EVENTS_BASAL_SUSPENSION = "PUMP_EVENTS_BASAL_SUSPENSION"
|
||||
PROFILES = "PROFILES"
|
||||
CGM_ALERTS = "CGM_ALERTS"
|
||||
DEVICE_STATUS = "DEVICE_STATUS"
|
||||
|
||||
DEFAULT_FEATURES = [
|
||||
BASAL,
|
||||
@@ -27,6 +28,7 @@ ALL_FEATURES = [
|
||||
PROFILES,
|
||||
CGM,
|
||||
CGM_ALERTS,
|
||||
DEVICE_STATUS,
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class ProcessDeviceStatus:
|
||||
self.features = features
|
||||
|
||||
def enabled(self):
|
||||
return features.PUMP_EVENTS in self.features
|
||||
return features.DEVICE_STATUS in self.features
|
||||
|
||||
def process(self, events, time_start, time_end):
|
||||
logger.debug("ProcessDeviceStatus: querying for last uploaded devicestatus")
|
||||
@@ -36,8 +36,8 @@ class ProcessDeviceStatus:
|
||||
|
||||
|
||||
last_daily_basal_event = None
|
||||
for event in sorted(events, key=lambda x: self.timestamp_for(x)):
|
||||
if last_upload_time and self.timestamp_for(event) <= last_upload_time:
|
||||
for event in sorted(events, key=lambda x: x.raw.timestamp):
|
||||
if last_upload_time and event.raw.timestamp <= last_upload_time:
|
||||
if self.pretend:
|
||||
logger.info("ProcessDeviceStatus: Skipping %s not after last upload time: %s (time range: %s - %s)" % (type(event), event, time_start, time_end))
|
||||
continue
|
||||
@@ -48,17 +48,18 @@ class ProcessDeviceStatus:
|
||||
|
||||
if not last_daily_basal_event:
|
||||
logger.info("ProcessDeviceStatus: No last_daily_basal_event found for add (time range: %s - %s)" % (time_start, time_end))
|
||||
return []
|
||||
|
||||
|
||||
ns_entries = []
|
||||
ns_entries.append(self.daily_basal_to_nsentry(last_daily_basal_event))
|
||||
return ns_entries
|
||||
|
||||
def daily_basal_to_nsentry(event):
|
||||
def daily_basal_to_nsentry(self, event):
|
||||
return NightscoutEntry.devicestatus(
|
||||
created_at=event.eventTimestamp.format(),
|
||||
batteryVoltage=(float(event.batterylipomillivolts or 0)/1000),
|
||||
batteryString="%s%s" % (event.batteryChargePercent, '%'),
|
||||
batteryString="%.0f%s" % (100*event.batteryChargePercent, '%'),
|
||||
pump_event_id = "%s" % event.seqNum
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user