Compare commits

...
9 Commits
Author SHA1 Message Date
James Woglom 9a2a4ca771 v2.1.6 2024-10-16 21:34:22 -04:00
James Woglom 54ba2ed7df profiles: sort and set enteredBy 2024-10-16 21:34:11 -04:00
James Woglom 2892eb8ace exclude empty pump profile segments 2024-10-16 21:13:41 -04:00
James Woglom 1d432982ad v2.1.5 with pypi upload fix 2024-10-07 21:59:01 -04:00
James Woglom 891c2e2c10 fix printf 2024-10-07 21:30:50 -04:00
James Woglom 7dc479c84b v2.1.4 2024-10-05 12:56:17 -04:00
James Woglom 0417fb9fd8 add IGNORE_ZERO_UNIT_BASAL 2024-10-05 12:55:59 -04:00
James Woglom b80d52662b v2.1.3 2024-10-03 01:00:16 -04:00
Zack FernandesandJames Woglom 51ac469f00 Fix choose_device import class name 2024-10-03 00:59:45 -04:00
9 changed files with 42 additions and 19 deletions
+1 -1
View File
@@ -28,6 +28,6 @@ jobs:
--outdir dist/
.
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
+1 -1
View File
@@ -1,6 +1,6 @@
[metadata]
name = tconnectsync
version = 2.1.2
version = 2.1.6
author = James Woglom
author_email = j@wogloms.net
description = Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
@@ -25,6 +25,9 @@ class PumpProfile:
carbEntry: int # 1 / 0
maxBolus: int # milliunits
def __post_init__(self):
self.tDependentSegs = [i for i in self.tDependentSegs if not i.skip]
@dataclass_json
@dataclass
class PumpProfiles:
+11 -8
View File
@@ -251,30 +251,33 @@ class NightscoutEntry:
return {
# insulin duration in hours; Nightscout JS bug requires all top-level fields to be strings
"dia": "%s" % (profile.insulinDuration / 60),
"carbratio": [
"carbratio": list(sorted([
{
"time": minutes_to_ns_time(segment.startTime),
"timeAsSeconds": segment.startTime * 60,
"value": segment.carbRatio / 1000 # milliunits->units
} for segment in profile.tDependentSegs
],
} for segment in profile.tDependentSegs if not segment.skip
], key=lambda x: x["timeAsSeconds"])),
"carbs_hr": NIGHTSCOUT_PROFILE_CARBS_HR_VALUE,
"delay": NIGHTSCOUT_PROFILE_DELAY_VALUE,
"sens": [ # Correction factor / isf
"sens": list(sorted([ # Correction factor / isf
{
"time": minutes_to_ns_time(segment.startTime),
"timeAsSeconds": segment.startTime * 60,
"value": segment.isf
} for segment in profile.tDependentSegs
],
"basal": [
} for segment in profile.tDependentSegs if not segment.skip
], key=lambda x: x["timeAsSeconds"])),
"basal": list(sorted([
{
"time": minutes_to_ns_time(segment.startTime),
"timeAsSeconds": segment.startTime * 60,
"value": segment.basalRate / 1000 # milliunits->units
} for segment in profile.tDependentSegs
],
], key=lambda x: x["timeAsSeconds"])),
"target_low": [
{
"time": "00:00",
+1
View File
@@ -79,6 +79,7 @@ NIGHTSCOUT_PROFILE_UPLOAD_MODE = get_one_of('NIGHTSCOUT_PROFILE_UPLOAD_MODE', 'a
# Default Nightscout profile segment fields which aren't stored by Tandem
NIGHTSCOUT_PROFILE_CARBS_HR_VALUE = get('NIGHTSCOUT_PROFILE_CARBS_HR_VALUE', '20')
NIGHTSCOUT_PROFILE_DELAY_VALUE = get('NIGHTSCOUT_PROFILE_DELAY_VALUE', '20')
IGNORE_ZERO_UNIT_BASAL = get_bool('IGNORE_ZERO_UNIT_BASAL', 'false')
ENABLE_TESTING_MODES = get_bool('ENABLE_TESTING_MODES', 'false')
SKIP_NS_LAST_UPLOADED_CHECK = get_bool('SKIP_NS_LAST_UPLOADED_CHECK', 'false')
@@ -1,5 +1,5 @@
from ...features import DEFAULT_FEATURES
from .choose_device import TandemSourceChooseDevice
from .choose_device import ChooseDevice
from .process import ProcessTimeRange
from ... import secret
@@ -13,5 +13,5 @@ def run_oneshot(tconnect, nightscout, pretend=False, features=DEFAULT_FEATURES,
if not secret_arg:
secret_arg = secret
tconnectDevice = TandemSourceChooseDevice(secret_arg, tconnect).choose()
return ProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend, features).process(time_start, time_end)
tconnectDevice = ChooseDevice(secret_arg, tconnect).choose()
return ProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend, features).process(time_start, time_end)
+4 -2
View File
@@ -82,7 +82,9 @@ class ProcessTimeRange:
if c.enabled():
logger.info("%s is enabled from features %s" % (clazz, self.features))
ns_entries = c.process(events, events_first_time, events_last_time)
processed_count += c.write(ns_entries)
w = c.write(ns_entries)
if w:
processed_count += w
else:
logger.info("Skipping %s, is not enabled from features %s" % (clazz, self.features))
@@ -95,6 +97,6 @@ class ProcessTimeRange:
else:
logger.info("Skipping %s, is not enabled from features %s" % (updater_class.__name__, self.features))
logger.info("Processed %d events. Last event ID seen: %d" % (processed_count, last_event_id))
logger.info("Processed %d events. Last event ID seen: %d" % (processed_count if processed_count else 0, last_event_id if last_event_id else -1))
return processed_count, last_event_id
@@ -1,6 +1,7 @@
import logging
import arrow
from ...secret import IGNORE_ZERO_UNIT_BASAL
from ...features import DEFAULT_FEATURES
from ... import features
from ...eventparser.generic import Events, decode_raw_events, EVENT_LEN
@@ -54,7 +55,9 @@ class ProcessBasal:
ns_entries = []
for item in with_duration:
ns_entries.append(self.basal_to_nsentry(*item))
ns = self.basal_to_nsentry(*item)
if ns:
ns_entries.append(ns)
return ns_entries
@@ -73,16 +76,24 @@ class ProcessBasal:
def basal_to_nsentry(self, start, duration, event):
if type(event) == eventtypes.LidBasalRateChange:
value = insulin_float_round(event.commandedbasalrate)
if IGNORE_ZERO_UNIT_BASAL and value < 0.01:
logger.info("Ignoring basal entry with %.2f unit basal because IGNORE_ZERO_UNIT_BASAL=true: %s" % (value, event))
return None
return NightscoutEntry.basal(
value = insulin_float_round(event.commandedbasalrate),
value = value,
duration_mins = duration.seconds / 60,
created_at = start.format(),
reason = ', '.join(bitmask_to_list(event.changetype)),
pump_event_id = "%s" % event.eventId
)
if type(event) == eventtypes.LidBasalDelivery:
value = insulin_milliunits_to_real(event.commandedRate)
if IGNORE_ZERO_UNIT_BASAL and value < 0.01:
logger.info("Ignoring basal entry with %.2f unit basal because IGNORE_ZERO_UNIT_BASAL=true: %s" % (value, event))
return None
return NightscoutEntry.basal(
value = insulin_milliunits_to_real(event.commandedRate),
value = value,
duration_mins = duration.seconds / 60,
created_at = start.format(),
reason = ', '.join(bitmask_to_list(event.commandedRateSource)),
@@ -8,7 +8,7 @@ from ...features import DEFAULT_FEATURES
from ... import features
from ...domain.tandemsource.pump_settings import PumpSettings
from ...parser.nightscout import (
NightscoutEntry
NightscoutEntry, ENTERED_BY
)
from ...secret import NIGHTSCOUT_PROFILE_UPLOAD_MODE
@@ -53,6 +53,8 @@ class UpdateProfiles:
if ns_profile_obj is None:
ns_profile_obj = {}
logger.info("Current Nightscout profile was authored by: %s" % (ns_profile_obj.get('enteredBy')))
diff, ns_profile_new = self.compare_profiles(pump_settings, ns_profile_obj)
if not diff:
logger.info("Pump and Nightscout profiles up to date")
@@ -145,6 +147,7 @@ class UpdateProfiles:
return False, ns_profile_obj
logger.info("New Nightscout profile object: %s", new_ns_profile)
new_ns_profile['enteredBy'] = ENTERED_BY
return True, new_ns_profile
def nightscout_profiles_identical(self, configured: dict, translated: dict) -> bool: