tconnectsync 3.0.1__tar.gz → 3.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tconnectsync-3.0.1/tconnectsync.egg-info → tconnectsync-3.0.4}/PKG-INFO +2 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/setup.cfg +2 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/api/tandemsource.py +18 -14
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/event_class.py +1 -1
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/build_events.py +30 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/events.py +2108 -646
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/static_dicts.py +1 -1
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/transforms.py +13 -6
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/parser/nightscout.py +24 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/autoupdate.py +46 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process.py +4 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cartridge.py +19 -8
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_alert.py +2 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_device_status.py +10 -11
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_user_mode.py +4 -4
- {tconnectsync-3.0.1 → tconnectsync-3.0.4/tconnectsync.egg-info}/PKG-INFO +2 -2
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync.egg-info/requires.txt +1 -1
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/LICENSE.md +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/README.md +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/pyproject.toml +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/setup.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/__main__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/api/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/api/common.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/check.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/domain/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/pump_settings.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/generic.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/raw_event.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/eventparser/utils.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/features.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/nightscout.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/parser/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/secret.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/choose_device.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/cli_helpers.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/helpers.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/heroku_helpers.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_alarm.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal_resume.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal_suspension.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_bolus.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_reading.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/update_profiles.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/util/__init__.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/util/cli.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync/util/constants.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync.egg-info/SOURCES.txt +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync.egg-info/dependency_links.txt +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync.egg-info/entry_points.txt +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tconnectsync.egg-info/top_level.txt +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tests/test_eu_region_integration.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tests/test_nightscout.py +0 -0
- {tconnectsync-3.0.1 → tconnectsync-3.0.4}/tests/test_secret.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tconnectsync
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.4
|
|
4
4
|
Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2 and Tandem Mobi
|
|
5
5
|
Home-page: https://github.com/jwoglom/tconnectsync
|
|
6
6
|
Author: James Woglom
|
|
@@ -22,7 +22,7 @@ Requires-Dist: pysocks
|
|
|
22
22
|
Requires-Dist: urllib3
|
|
23
23
|
Requires-Dist: requests
|
|
24
24
|
Requires-Dist: requests-oidc
|
|
25
|
-
Requires-Dist: PyJWT
|
|
25
|
+
Requires-Dist: PyJWT<3,>=2.8.0
|
|
26
26
|
Requires-Dist: cryptography==43.0.1; python_version < "3.9"
|
|
27
27
|
Requires-Dist: cryptography; python_version >= "3.9"
|
|
28
28
|
Requires-Dist: dataclasses-json
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = tconnectsync
|
|
3
|
-
version = 3.0.
|
|
3
|
+
version = 3.0.4
|
|
4
4
|
author = James Woglom
|
|
5
5
|
author_email = j@wogloms.net
|
|
6
6
|
description = Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2 and Tandem Mobi
|
|
@@ -30,7 +30,7 @@ install_requires =
|
|
|
30
30
|
urllib3
|
|
31
31
|
requests
|
|
32
32
|
requests-oidc
|
|
33
|
-
PyJWT
|
|
33
|
+
PyJWT>=2.8.0,<3
|
|
34
34
|
cryptography==43.0.1; python_version < "3.9"
|
|
35
35
|
cryptography; python_version >= "3.9"
|
|
36
36
|
dataclasses-json
|
|
@@ -9,7 +9,7 @@ import os
|
|
|
9
9
|
import jwt
|
|
10
10
|
import pickle
|
|
11
11
|
|
|
12
|
-
from typing import Any, Dict, Iterator, List, Optional, Tuple
|
|
12
|
+
from typing import Any, Dict, Iterator, List, Optional, Tuple, cast
|
|
13
13
|
try:
|
|
14
14
|
from typing import TypedDict
|
|
15
15
|
except ImportError: # Python 3.7
|
|
@@ -409,25 +409,27 @@ class TandemSourceApi:
|
|
|
409
409
|
# login outright.
|
|
410
410
|
id_token_claims: JwtClaims
|
|
411
411
|
try:
|
|
412
|
-
id_token_claims = jwt.decode(
|
|
412
|
+
id_token_claims = cast(JwtClaims, jwt.decode(
|
|
413
413
|
id_token,
|
|
414
414
|
key=key,
|
|
415
415
|
algorithms=['RS256'],
|
|
416
|
+
leeway=60, # tolerate small clock skew between this machine and the identity provider
|
|
416
417
|
audience=audience,
|
|
417
418
|
issuer=issuer,
|
|
418
|
-
)
|
|
419
|
+
))
|
|
419
420
|
except jwt.InvalidAudienceError:
|
|
420
421
|
logger.warning(
|
|
421
422
|
"id_token audience did not match client_id %s; decoding without audience verification",
|
|
422
423
|
audience,
|
|
423
424
|
)
|
|
424
|
-
id_token_claims = jwt.decode(
|
|
425
|
+
id_token_claims = cast(JwtClaims, jwt.decode(
|
|
425
426
|
id_token,
|
|
426
427
|
key=key,
|
|
427
428
|
algorithms=['RS256'],
|
|
429
|
+
leeway=60, # tolerate small clock skew between this machine and the identity provider
|
|
428
430
|
issuer=issuer,
|
|
429
431
|
options={"verify_aud": False},
|
|
430
|
-
)
|
|
432
|
+
))
|
|
431
433
|
|
|
432
434
|
logger.info("Decoded JWT: %s" % json.dumps(id_token_claims))
|
|
433
435
|
|
|
@@ -608,8 +610,8 @@ class TandemSourceApi:
|
|
|
608
610
|
return self.get('api/reports/bff/pumper/%s' % (self.pumperId), {})
|
|
609
611
|
|
|
610
612
|
# Matches the Tandem Source web app's getLogIDList() (55 IDs) as observed in
|
|
611
|
-
# the live GET api/reports/bff/pump-logs request.
|
|
612
|
-
DEFAULT_EVENT_IDS: List[int] = [229,5,28,4,26,99,279,3,16,59,21,55,20,280,64,65,66,61,33,371,171,369,460,172,370,461,372,480,399,256,213,406,477,394,212,404,214,405,486,447,313,60,14,6,90,230,140,12,11,53,13,63,203,307,191]
|
|
613
|
+
# the live GET api/reports/bff/pump-logs request.
|
|
614
|
+
DEFAULT_EVENT_IDS: List[int] = [229,5,28,4,26,562,563,566,99,279,3,16,59,21,55,20,280,64,65,66,61,33,371,171,369,460,172,370,461,372,480,399,256,213,406,477,394,212,404,214,405,486,447,313,60,14,69,57,6,90,230,140,12,11,53,559,558,565,564,13,63,203,307,191]
|
|
613
615
|
|
|
614
616
|
def get_pump_logs(self, device_id: str, min_date: Optional[str] = None, max_date: Optional[str] = None, event_ids_filter: Optional[List[int]] = DEFAULT_EVENT_IDS) -> PumpLogsResponse:
|
|
615
617
|
"""Fetch pre-decoded pump events for a single date window from the BFF
|
|
@@ -619,20 +621,22 @@ class TandemSourceApi:
|
|
|
619
621
|
The server caps the window at ~4 weeks; callers needing a longer range
|
|
620
622
|
must page by date window (see pump_events).
|
|
621
623
|
|
|
622
|
-
Note:
|
|
623
|
-
|
|
624
|
-
the
|
|
625
|
-
|
|
624
|
+
Note: as of ~2026-10, the server rejects an unrecognized eventIds key
|
|
625
|
+
with HTTP 400 (ZodError) -- it was renamed to eventCodes (see #163).
|
|
626
|
+
Historically the server ignored this filter and returned every event
|
|
627
|
+
in the window regardless, so the effective filtering happens
|
|
628
|
+
client-side via EventClass dispatch. We still send eventCodes to
|
|
629
|
+
mirror the web app and stay forward-compatible."""
|
|
626
630
|
minDate = parse_ymd_date(min_date)
|
|
627
631
|
maxDate = parse_ymd_date(max_date)
|
|
628
632
|
logger.debug(f'get_pump_logs({device_id}, {minDate}, {maxDate})')
|
|
629
633
|
|
|
630
|
-
query = urllib.parse.urlencode({
|
|
634
|
+
query = urllib.parse.urlencode({k: v for k, v in {
|
|
631
635
|
'pumperId': self.pumperId,
|
|
632
636
|
'startDate': '%sT00:00:00Z' % minDate,
|
|
633
637
|
'endDate': '%sT23:59:59Z' % maxDate,
|
|
634
|
-
'
|
|
635
|
-
})
|
|
638
|
+
'eventCodes': ','.join(map(str, event_ids_filter)) if event_ids_filter else '',
|
|
639
|
+
}.items() if v})
|
|
636
640
|
return self.get('api/reports/bff/pump-logs/%s?%s' % (device_id, query), {})
|
|
637
641
|
|
|
638
642
|
# The pump-logs endpoint caps each request at roughly four weeks, so a
|
|
@@ -17,7 +17,7 @@ class EventClass(set, Enum): # type: ignore[misc] # set/Enum both define __has
|
|
|
17
17
|
events.LidBolexCompleted # extended bolus
|
|
18
18
|
}
|
|
19
19
|
CARTRIDGE = {events.LidCartridgeFilled, events.LidCannulaFilled, events.LidTubingFilled}
|
|
20
|
-
CGM_ALERT = {events.LidCgmAlertActivated, events.LidCgmAlertActivatedDex, events.
|
|
20
|
+
CGM_ALERT = {events.LidCgmAlertActivated, events.LidCgmAlertActivatedDex, events.LidCgmAlertActivatedAbt}
|
|
21
21
|
_CGM_START = {events.LidCgmStartSessionGx, events.LidCgmStartSessionFsl2}
|
|
22
22
|
_CGM_JOIN = {events.LidCgmJoinSessionGx, events.LidCgmJoinSessionG7, events.LidCgmJoinSessionFsl2, events.LidCgmJoinSessionFsl3}
|
|
23
23
|
_CGM_STOP = {events.LidCgmStopSessionGx, events.LidCgmStopSessionG7, events.LidCgmStopSessionFsl2, events.LidCgmStopSessionFsl3}
|
|
@@ -52,8 +52,30 @@ TYPE_TO_PYOBJ = {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
HEADER_SIZE = 10
|
|
55
|
+
TYPE_TO_NUM_BYTES = {
|
|
56
|
+
'uint8': 1,
|
|
57
|
+
'int8': 1,
|
|
58
|
+
'uint16': 2,
|
|
59
|
+
'int16': 2,
|
|
60
|
+
'uint32': 4,
|
|
61
|
+
'float32': 4,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def yml_offset_to_data_field_offset(yml_offset, field_type):
|
|
65
|
+
# Schema offsets address each 4-byte word little-endian, while the event
|
|
66
|
+
# bytes are big-endian, so mirror the field within its word. Port of
|
|
67
|
+
# ymlOffsetToDataFieldOffset in Tandem's reports-module Decoder.
|
|
68
|
+
num_bytes = TYPE_TO_NUM_BYTES[field_type]
|
|
69
|
+
word_base = (yml_offset // 4) * 4
|
|
70
|
+
byte_in_word = yml_offset % 4
|
|
71
|
+
converted = word_base + (4 - num_bytes - byte_in_word)
|
|
72
|
+
if converted < 0:
|
|
73
|
+
raise ValueError(f"Invalid YML offset '{yml_offset}' for field type '{field_type}'")
|
|
74
|
+
return converted
|
|
75
|
+
|
|
55
76
|
def unpack_command_for(field_def):
|
|
56
|
-
|
|
77
|
+
offset = HEADER_SIZE + yml_offset_to_data_field_offset(field_def["offset"], field_def["type"])
|
|
78
|
+
return f'struct.unpack_from({field_def["type"].upper()}, raw[:EVENT_LEN], {offset})'
|
|
57
79
|
|
|
58
80
|
TEMPLATE = '''
|
|
59
81
|
@dataclass
|
|
@@ -188,8 +210,14 @@ def build_transform_funcs(event_def):
|
|
|
188
210
|
if not "transform" in field:
|
|
189
211
|
continue
|
|
190
212
|
|
|
213
|
+
# Each transform defines the field's property, so only the first one
|
|
214
|
+
# that applies is used (e.g. our curated alert dictionary over the
|
|
215
|
+
# schema's own enum mapping for the same field).
|
|
191
216
|
for tx in field["transform"]:
|
|
192
|
-
|
|
217
|
+
out = TRANSFORMS[tx[0]](event_def, name, fieldNameFormat(name), field, tx[1] if len(tx) > 1 else None)
|
|
218
|
+
if out:
|
|
219
|
+
ret += out
|
|
220
|
+
break
|
|
193
221
|
|
|
194
222
|
return '\n'.join([f'{" "*4}{f}' if f else '' for f in ret])
|
|
195
223
|
|