Skip to content

Commit

Permalink
devicestatus: set pump.battery.percent
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoglom committed Dec 13, 2024
1 parent fb9588f commit d1341e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions tconnectsync/parser/nightscout.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ def activity(created_at, duration, reason="", event_type=ACTIVITY_EVENTTYPE, pum
}

@staticmethod
def devicestatus(created_at, batteryVoltage, batteryString, pump_event_id=""):
def devicestatus(created_at, batteryVoltage, batteryPercent, pump_event_id=""):
return {
"device": ENTERED_BY,
"created_at": created_at,
"pump": {
"battery": {
"voltage": float(batteryVoltage),
"string": batteryString
"percent": int(batteryPercent) if batteryPercent else None,
"status": "%.0f%s" % (batteryPercent, '%')
},
},
"pump_event_id": pump_event_id
Expand Down
2 changes: 1 addition & 1 deletion tconnectsync/sync/tandemsource/process_device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def daily_basal_to_nsentry(self, event):
return NightscoutEntry.devicestatus(
created_at=event.eventTimestamp.format(),
batteryVoltage=(float(event.batterylipomillivolts or 0)/1000),
batteryString="%.0f%s" % (100*event.batteryChargePercent, '%'),
batteryPercent=int(100*event.batteryChargePercent),
pump_event_id = "%s" % event.seqNum
)

Expand Down
9 changes: 6 additions & 3 deletions tests/sync/tandemsource/test_process_device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_single_event_no_last_uploaded(self):
'device': 'Pump (tconnectsync)',
'pump': {
'battery': {
'string': '48%',
'status': '48%',
'percent': 48,
'voltage': 14.08
}
},
Expand Down Expand Up @@ -90,7 +91,8 @@ def test_multiple_event_with_last_uploaded(self):
'device': 'Pump (tconnectsync)',
'pump': {
'battery': {
'string': '47%',
'status': '47%',
'percent': 47,
'voltage': 13.824
}
},
Expand Down Expand Up @@ -132,7 +134,8 @@ def test_multiple_event_only_latest_applied(self):
'device': 'Pump (tconnectsync)',
'pump': {
'battery': {
'string': '46%',
'status': '46%',
'percent': 46,
'voltage': 13.568
}
},
Expand Down

0 comments on commit d1341e0

Please sign in to comment.