tconnectsync 3.0.3__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.
Files changed (61) hide show
  1. {tconnectsync-3.0.3/tconnectsync.egg-info → tconnectsync-3.0.4}/PKG-INFO +2 -2
  2. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/setup.cfg +2 -2
  3. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/api/tandemsource.py +9 -7
  4. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/event_class.py +1 -1
  5. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/build_events.py +30 -2
  6. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/events.py +2108 -646
  7. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/static_dicts.py +1 -1
  8. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/transforms.py +13 -6
  9. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/parser/nightscout.py +24 -0
  10. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/autoupdate.py +46 -2
  11. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process.py +4 -0
  12. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cartridge.py +19 -8
  13. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_alert.py +2 -2
  14. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_device_status.py +10 -11
  15. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_user_mode.py +4 -4
  16. {tconnectsync-3.0.3 → tconnectsync-3.0.4/tconnectsync.egg-info}/PKG-INFO +2 -2
  17. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync.egg-info/requires.txt +1 -1
  18. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/LICENSE.md +0 -0
  19. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/README.md +0 -0
  20. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/pyproject.toml +0 -0
  21. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/setup.py +0 -0
  22. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/__init__.py +0 -0
  23. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/__main__.py +0 -0
  24. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/api/__init__.py +0 -0
  25. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/api/common.py +0 -0
  26. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/check.py +0 -0
  27. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/domain/__init__.py +0 -0
  28. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/__init__.py +0 -0
  29. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/domain/tandemsource/pump_settings.py +0 -0
  30. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/__init__.py +0 -0
  31. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/generic.py +0 -0
  32. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/raw_event.py +0 -0
  33. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/eventparser/utils.py +0 -0
  34. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/features.py +0 -0
  35. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/nightscout.py +0 -0
  36. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/parser/__init__.py +0 -0
  37. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/secret.py +0 -0
  38. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/__init__.py +0 -0
  39. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/__init__.py +0 -0
  40. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/choose_device.py +0 -0
  41. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/cli_helpers.py +0 -0
  42. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/helpers.py +0 -0
  43. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/heroku_helpers.py +0 -0
  44. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_alarm.py +0 -0
  45. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal.py +0 -0
  46. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal_resume.py +0 -0
  47. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_basal_suspension.py +0 -0
  48. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_bolus.py +0 -0
  49. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_reading.py +0 -0
  50. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +0 -0
  51. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/sync/tandemsource/update_profiles.py +0 -0
  52. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/util/__init__.py +0 -0
  53. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/util/cli.py +0 -0
  54. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync/util/constants.py +0 -0
  55. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync.egg-info/SOURCES.txt +0 -0
  56. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync.egg-info/dependency_links.txt +0 -0
  57. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync.egg-info/entry_points.txt +0 -0
  58. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tconnectsync.egg-info/top_level.txt +0 -0
  59. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tests/test_eu_region_integration.py +0 -0
  60. {tconnectsync-3.0.3 → tconnectsync-3.0.4}/tests/test_nightscout.py +0 -0
  61. {tconnectsync-3.0.3 → 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
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==2.8.0
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
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==2.8.0
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
 
@@ -629,12 +631,12 @@ class TandemSourceApi:
629
631
  maxDate = parse_ymd_date(max_date)
630
632
  logger.debug(f'get_pump_logs({device_id}, {minDate}, {maxDate})')
631
633
 
632
- query = urllib.parse.urlencode({
634
+ query = urllib.parse.urlencode({k: v for k, v in {
633
635
  'pumperId': self.pumperId,
634
636
  'startDate': '%sT00:00:00Z' % minDate,
635
637
  'endDate': '%sT23:59:59Z' % maxDate,
636
638
  'eventCodes': ','.join(map(str, event_ids_filter)) if event_ids_filter else '',
637
- })
639
+ }.items() if v})
638
640
  return self.get('api/reports/bff/pump-logs/%s?%s' % (device_id, query), {})
639
641
 
640
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.LidCgmAlertActivatedFsl2}
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
- return f'struct.unpack_from({field_def["type"].upper()}, raw[:EVENT_LEN], {HEADER_SIZE + field_def["offset"]})'
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
- ret += TRANSFORMS[tx[0]](event_def, name, fieldNameFormat(name), field, tx[1])
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