tconnectsync 2.2.4__tar.gz → 2.3.1__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 (79) hide show
  1. {tconnectsync-2.2.4/tconnectsync.egg-info → tconnectsync-2.3.1}/PKG-INFO +5 -1
  2. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/README.md +4 -0
  3. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/setup.cfg +1 -1
  4. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/__init__.py +10 -8
  5. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/__init__.py +4 -3
  6. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/tandemsource.py +70 -14
  7. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/check.py +67 -98
  8. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/secret.py +1 -0
  9. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/autoupdate.py +5 -2
  10. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/cli_helpers.py +2 -2
  11. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/util/cli.py +2 -2
  12. {tconnectsync-2.2.4 → tconnectsync-2.3.1/tconnectsync.egg-info}/PKG-INFO +5 -1
  13. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync.egg-info/SOURCES.txt +0 -16
  14. tconnectsync-2.2.4/tconnectsync/autoupdate.py +0 -207
  15. tconnectsync-2.2.4/tconnectsync/sync/basal.py +0 -161
  16. tconnectsync-2.2.4/tconnectsync/sync/bolus.py +0 -120
  17. tconnectsync-2.2.4/tconnectsync/sync/cgm.py +0 -69
  18. tconnectsync-2.2.4/tconnectsync/sync/iob.py +0 -59
  19. tconnectsync-2.2.4/tconnectsync/sync/profile.py +0 -200
  20. tconnectsync-2.2.4/tconnectsync/sync/pump_events.py +0 -218
  21. tconnectsync-2.2.4/tests/test_autoupdate.py +0 -368
  22. tconnectsync-2.2.4/tests/test_process.py +0 -978
  23. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/LICENSE.md +0 -0
  24. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/pyproject.toml +0 -0
  25. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/setup.py +0 -0
  26. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/__main__.py +0 -0
  27. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/android.py +0 -0
  28. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/common.py +0 -0
  29. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/controliq.py +0 -0
  30. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/webui.py +0 -0
  31. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/api/ws2.py +0 -0
  32. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/__init__.py +0 -0
  33. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/bolus.py +0 -0
  34. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/device_settings.py +0 -0
  35. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/tandemsource/__init__.py +0 -0
  36. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/tandemsource/event_class.py +0 -0
  37. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/tandemsource/pump_settings.py +0 -0
  38. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/therapy_event.py +0 -0
  39. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/domain/utility.py +0 -0
  40. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/__init__.py +0 -0
  41. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/build_events.py +0 -0
  42. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/events.py +0 -0
  43. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/generic.py +0 -0
  44. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/raw_event.py +0 -0
  45. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/static_dicts.py +0 -0
  46. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/transforms.py +0 -0
  47. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/eventparser/utils.py +0 -0
  48. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/features.py +0 -0
  49. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/nightscout.py +0 -0
  50. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/parser/__init__.py +0 -0
  51. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/parser/ciq_therapy_events.py +0 -0
  52. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/parser/nightscout.py +0 -0
  53. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/parser/tconnect.py +0 -0
  54. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/process.py +0 -0
  55. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/__init__.py +0 -0
  56. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/__init__.py +0 -0
  57. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/choose_device.py +0 -0
  58. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/helpers.py +0 -0
  59. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/heroku_helpers.py +0 -0
  60. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process.py +0 -0
  61. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_alarm.py +0 -0
  62. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_basal.py +0 -0
  63. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_basal_resume.py +0 -0
  64. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_basal_suspension.py +0 -0
  65. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_bolus.py +0 -0
  66. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_cartridge.py +0 -0
  67. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_cgm_alert.py +0 -0
  68. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_cgm_reading.py +0 -0
  69. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +0 -0
  70. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_device_status.py +0 -0
  71. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/process_user_mode.py +0 -0
  72. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/sync/tandemsource/update_profiles.py +0 -0
  73. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/util/__init__.py +0 -0
  74. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync/util/constants.py +0 -0
  75. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync.egg-info/dependency_links.txt +0 -0
  76. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync.egg-info/entry_points.txt +0 -0
  77. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync.egg-info/requires.txt +0 -0
  78. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tconnectsync.egg-info/top_level.txt +0 -0
  79. {tconnectsync-2.2.4 → tconnectsync-2.3.1}/tests/test_secret.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tconnectsync
3
- Version: 2.2.4
3
+ Version: 2.3.1
4
4
  Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
5
5
  Home-page: https://github.com/jwoglom/tconnectsync
6
6
  Author: James Woglom
@@ -120,6 +120,9 @@ You should specify the following parameters:
120
120
  TCONNECT_EMAIL='email@email.com'
121
121
  TCONNECT_PASSWORD='password'
122
122
 
123
+ # OPTIONAL: Your region (US or EU)
124
+ TCONNECT_REGION=US
125
+
123
126
  # URL of your Nightscout site
124
127
  NS_URL='https://yournightscouturl/'
125
128
  # Your Nightscout API_SECRET value
@@ -130,6 +133,7 @@ TIMEZONE_NAME='America/New_York'
130
133
 
131
134
  # OPTIONAL: Your pump's serial number (numeric)
132
135
  PUMP_SERIAL_NUMBER=11111111
136
+
133
137
  ```
134
138
 
135
139
  This file contains your t:connect username and password, Tandem pump serial number (which is utilized in API calls to t:connect), your Nightscout URL and secret token (for uploading data to Nightscout), and local timezone (the timezone used in t:connect). When specifying the timezone, enter a [TZ database name value](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
@@ -89,6 +89,9 @@ You should specify the following parameters:
89
89
  TCONNECT_EMAIL='email@email.com'
90
90
  TCONNECT_PASSWORD='password'
91
91
 
92
+ # OPTIONAL: Your region (US or EU)
93
+ TCONNECT_REGION=US
94
+
92
95
  # URL of your Nightscout site
93
96
  NS_URL='https://yournightscouturl/'
94
97
  # Your Nightscout API_SECRET value
@@ -99,6 +102,7 @@ TIMEZONE_NAME='America/New_York'
99
102
 
100
103
  # OPTIONAL: Your pump's serial number (numeric)
101
104
  PUMP_SERIAL_NUMBER=11111111
105
+
102
106
  ```
103
107
 
104
108
  This file contains your t:connect username and password, Tandem pump serial number (which is utilized in API calls to t:connect), your Nightscout URL and secret token (for uploading data to Nightscout), and local timezone (the timezone used in t:connect). When specifying the timezone, enter a [TZ database name value](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = tconnectsync
3
- version = 2.2.4
3
+ version = 2.3.1
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
@@ -12,8 +12,6 @@ if sys.version_info < (3, 8):
12
12
  typing.Protocol = typing_extensions.Protocol
13
13
 
14
14
  from .api import TConnectApi
15
- from .process import process_time_range
16
- from .autoupdate import Autoupdate
17
15
  from .sync.tandemsource.autoupdate import TandemSourceAutoupdate
18
16
  from .sync.tandemsource.choose_device import ChooseDevice as TandemSourceChooseDevice
19
17
  from .sync.tandemsource.process import ProcessTimeRange as TandemSourceProcessTimeRange
@@ -25,6 +23,7 @@ try:
25
23
  from .secret import (
26
24
  TCONNECT_EMAIL,
27
25
  TCONNECT_PASSWORD,
26
+ TCONNECT_REGION,
28
27
  NS_URL,
29
28
  NS_SECRET,
30
29
  NS_SKIP_TLS_VERIFY,
@@ -53,7 +52,8 @@ def parse_args(*args, **kwargs):
53
52
  parser.add_argument('--auto-update', dest='auto_update', action='store_const', const=True, default=False, help='If set, continuously checks for updates from t:connect and syncs with Nightscout.')
54
53
  parser.add_argument('--check-login', dest='check_login', action='store_const', const=True, default=False, help='If set, checks that the provided t:connect credentials can be used to log in.')
55
54
  parser.add_argument('--features', dest='features', nargs='+', default=DEFAULT_FEATURES, choices=ALL_FEATURES, help='Specifies what data should be synchronized between tconnect and Nightscout.')
56
- parser.add_argument('--tandem-source', dest='tandem_source', action='store_const', const=True, default=False, help='FOR TESTING: Use Tandem Source')
55
+ parser.add_argument('--tandem-source', dest='tandem_source', action='store_const', const=True, default=True, help=argparse.SUPPRESS) # no longer used
56
+ parser.add_argument('--region', dest='region', type=str, choices=['US', 'EU'], default=None, help='Tandem t:connect server region (US or EU). If not specified, uses TCONNECT_REGION from configuration or defaults to US.')
57
57
 
58
58
  return parser.parse_args(*args, **kwargs)
59
59
 
@@ -85,6 +85,8 @@ def main(*args, **kwargs):
85
85
  if time_end < time_start:
86
86
  raise Exception('time_start must be before time_end')
87
87
 
88
+ # Determine region: command line arg takes precedence, then config, then default to US
89
+ region = args.region if args.region else TCONNECT_REGION
88
90
 
89
91
  if TCONNECT_EMAIL == 'email@email.com':
90
92
  logging.warn('NO USERNAME WAS PROVIDED. Ensure you have set TCONNECT_EMAIL appropriately.')
@@ -98,18 +100,18 @@ def main(*args, **kwargs):
98
100
  else:
99
101
  logging.warn('NO PUMP SERIAL NUMBER WAS PROVIDED. Ensure you have set PUMP_SERIAL_NUMBER appropriately.')
100
102
 
101
- tconnect = TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD)
103
+ tconnect = TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD, region)
102
104
 
103
105
  nightscout = NightscoutApi(NS_URL, NS_SECRET, skip_verify=NS_SKIP_TLS_VERIFY, ignore_conn_errors=NS_IGNORE_CONN_ERRORS)
104
106
 
105
- # NOT YET MIGRATED
106
- # if args.check_login:
107
- # return check_login(tconnect, time_start, time_end)
107
+ if args.check_login:
108
+ return check_login(tconnect, time_start, time_end)
108
109
 
109
110
  logging.warning("THIS VERSION OF TCONNECTSYNC READS DATA FROM TANDEM SOURCE, AND MAY CONTAIN BUGS!")
110
111
  logging.info("You may notice different behavior compared to older versions which utilized t:connect data sources.")
111
112
  logging.info("To report a bug or to get help, see https://github.com/jwoglom/tconnectsync/issues")
112
113
 
114
+ logging.info(f"Using Tandem t:connect region: {region}")
113
115
  logging.info("Enabled features: " + ", ".join(args.features))
114
116
 
115
117
  if args.check_login:
@@ -117,7 +119,7 @@ def main(*args, **kwargs):
117
119
 
118
120
  if args.auto_update:
119
121
  u = TandemSourceAutoupdate(secret)
120
- sys.exit(u.process(tconnect, nightscout, time_start, time_end, args.pretend, features=args.features))
122
+ sys.exit(u.process(tconnect, nightscout, args.pretend, features=args.features))
121
123
  else:
122
124
  tconnectDevice = TandemSourceChooseDevice(secret, tconnect).choose()
123
125
  added, last_event_id = TandemSourceProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend=args.pretend, secret=secret, features=args.features).process(time_start, time_end)
@@ -13,9 +13,10 @@ class TConnectApi:
13
13
  email = None
14
14
  password = None
15
15
 
16
- def __init__(self, email, password):
16
+ def __init__(self, email, password, region='US'):
17
17
  self.email = email
18
18
  self.password = password
19
+ self.region = region
19
20
  self._ciq = None
20
21
  self._ws2 = None
21
22
  self._android = None
@@ -27,9 +28,9 @@ class TConnectApi:
27
28
  if self._tandemsource and not self._tandemsource.needs_relogin():
28
29
  return self._tandemsource
29
30
 
30
- logger.debug("Instantiating new TandemSourceApi")
31
+ logger.debug(f"Instantiating new TandemSourceApi for region {self.region}")
31
32
 
32
- self._tandemsource = TandemSourceApi(self.email, self.password)
33
+ self._tandemsource = TandemSourceApi(self.email, self.password, self.region)
33
34
  return self._tandemsource
34
35
 
35
36
 
@@ -24,23 +24,73 @@ from ..eventparser.generic import Events, decode_raw_events, EVENT_LEN
24
24
  logger = logging.getLogger(__name__)
25
25
 
26
26
  class TandemSourceApi:
27
+ # Common URLs that are shared between regions
27
28
  LOGIN_PAGE_URL = 'https://sso.tandemdiabetes.com/'
28
- LOGIN_API_URL = 'https://tdcservices.tandemdiabetes.com/accounts/api/login'
29
29
  TDC_AUTH_CALLBACK_URL = 'https://sso.tandemdiabetes.com/auth/callback'
30
- TDC_OAUTH_AUTHORIZE_URL = 'https://tdcservices.tandemdiabetes.com/accounts/api/oauth2/v1/authorize'
31
- TDC_OIDC_JWKS_URL = 'https://tdcservices.tandemdiabetes.com/accounts/api/.well-known/openid-configuration/jwks'
32
- TDC_OIDC_ISSUER = 'https://tdcservices.tandemdiabetes.com/accounts/api' # openid_config['issuer']
33
- TDC_OIDC_CLIENT_ID = '0oa27ho9tpZE9Arjy4h7'
34
- SOURCE_URL = 'https://source.tandemdiabetes.com/'
35
-
36
-
37
- def __init__(self, email, password):
30
+
31
+ # US Region URLs (default)
32
+ _US_URLS = {
33
+ 'LOGIN_API_URL': 'https://tdcservices.tandemdiabetes.com/accounts/api/login',
34
+ 'TDC_OAUTH_AUTHORIZE_URL': 'https://tdcservices.tandemdiabetes.com/accounts/api/oauth2/v1/authorize',
35
+ 'TDC_OIDC_JWKS_URL': 'https://tdcservices.tandemdiabetes.com/accounts/api/.well-known/openid-configuration/jwks',
36
+ 'TDC_OIDC_ISSUER': 'https://tdcservices.tandemdiabetes.com/accounts/api',
37
+ 'TDC_OIDC_CLIENT_ID': '0oa27ho9tpZE9Arjy4h7',
38
+ 'SOURCE_URL': 'https://source.tandemdiabetes.com/',
39
+ 'REDIRECT_URI': 'https://sso.tandemdiabetes.com/auth/callback',
40
+ 'TOKEN_ENDPOINT': 'https://tdcservices.tandemdiabetes.com/accounts/api/connect/token',
41
+ 'AUTHORIZATION_ENDPOINT': 'https://tdcservices.tandemdiabetes.com/accounts/api/connect/authorize'
42
+ }
43
+
44
+ # EU Region URLs
45
+ _EU_URLS = {
46
+ 'LOGIN_API_URL': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api/login',
47
+ 'TDC_OAUTH_AUTHORIZE_URL': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api/oauth2/v1/authorize',
48
+ 'TDC_OIDC_JWKS_URL': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api/.well-known/openid-configuration/jwks',
49
+ 'TDC_OIDC_ISSUER': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api',
50
+ 'TDC_OIDC_CLIENT_ID': '1519e414-eeec-492e-8c5e-97bea4815a10',
51
+ 'SOURCE_URL': 'https://source.eu.tandemdiabetes.com/',
52
+ 'REDIRECT_URI': 'https://source.eu.tandemdiabetes.com/authorize/callback',
53
+ 'TOKEN_ENDPOINT': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api/connect/token',
54
+ 'AUTHORIZATION_ENDPOINT': 'https://tdcservices.eu.tandemdiabetes.com/accounts/api/connect/authorize'
55
+ }
56
+
57
+ def __init__(self, email, password, region='US'):
58
+ self.region = region.upper()
59
+ if self.region not in ['US', 'EU']:
60
+ raise ValueError(f"Invalid region '{region}'. Must be 'US' or 'EU'.")
61
+
62
+ self._region_urls = self._US_URLS if self.region == 'US' else self._EU_URLS
63
+
38
64
  self.login(email, password)
39
65
  self._email = email
40
66
  self._password = password
41
67
 
68
+ @property
69
+ def LOGIN_API_URL(self):
70
+ return self._region_urls['LOGIN_API_URL']
71
+
72
+ @property
73
+ def TDC_OAUTH_AUTHORIZE_URL(self):
74
+ return self._region_urls['TDC_OAUTH_AUTHORIZE_URL']
75
+
76
+ @property
77
+ def TDC_OIDC_JWKS_URL(self):
78
+ return self._region_urls['TDC_OIDC_JWKS_URL']
79
+
80
+ @property
81
+ def TDC_OIDC_ISSUER(self):
82
+ return self._region_urls['TDC_OIDC_ISSUER']
83
+
84
+ @property
85
+ def TDC_OIDC_CLIENT_ID(self):
86
+ return self._region_urls['TDC_OIDC_CLIENT_ID']
87
+
88
+ @property
89
+ def SOURCE_URL(self):
90
+ return self._region_urls['SOURCE_URL']
91
+
42
92
  def login(self, email, password):
43
- logger.info("Logging in to TandemSourceApi...")
93
+ logger.info(f"Logging in to TandemSourceApi ({self.region} region)...")
44
94
  if self.try_load_cached_creds(email):
45
95
  logger.info("Successfully used cached credentials")
46
96
  return True
@@ -70,11 +120,10 @@ class TandemSourceApi:
70
120
 
71
121
  # oidc
72
122
  client_id = self.TDC_OIDC_CLIENT_ID
73
- redirect_uri = 'https://sso.tandemdiabetes.com/auth/callback' # must be an allowlisted URI
123
+ redirect_uri = self._region_urls['REDIRECT_URI']
74
124
  scope = 'openid profile email'
75
125
 
76
- token_endpoint = 'https://tdcservices.tandemdiabetes.com/accounts/api/connect/token' #openid_config['token_endpoint']
77
-
126
+ token_endpoint = self._region_urls['TOKEN_ENDPOINT']
78
127
 
79
128
  def generate_code_verifier():
80
129
  """Generates a high-entropy code verifier."""
@@ -91,7 +140,7 @@ class TandemSourceApi:
91
140
  code_verifier = generate_code_verifier()
92
141
  code_challenge = generate_code_challenge(code_verifier)
93
142
 
94
- authorization_endpoint = 'https://tdcservices.tandemdiabetes.com/accounts/api/connect/authorize' #openid_config['authorization_endpoint']
143
+ authorization_endpoint = self._region_urls['AUTHORIZATION_ENDPOINT']
95
144
 
96
145
  oidc_step1_params = {
97
146
  'client_id': client_id,
@@ -224,6 +273,12 @@ class TandemSourceApi:
224
273
  logger.warning(f"Cached credentials are for a different email ({_saved_blob['cache_creds_email']} in cache, but using {email}), skipping")
225
274
  return False
226
275
 
276
+ # Check if cached region matches current region
277
+ cached_region = _saved_blob.get('cache_creds_region', 'US') # Default to US for backward compatibility
278
+ if cached_region != self.region:
279
+ logger.warning(f"Cached credentials are for a different region ({cached_region} in cache, but using {self.region}), skipping")
280
+ return False
281
+
227
282
  at_expiry = _saved_blob['accessTokenExpiresAt']
228
283
  if arrow.get().int_timestamp >= arrow.get(at_expiry).int_timestamp:
229
284
  logger.info(f"Cached credentials have expired ({_saved_blob['accessTokenExpiresAt']}), skipping")
@@ -278,6 +333,7 @@ class TandemSourceApi:
278
333
  'cache_creds_version': 1.0,
279
334
  'cache_creds_saved_at': arrow.get(),
280
335
  'cache_creds_email': email,
336
+ 'cache_creds_region': self.region, # Store the region in cache
281
337
  'jwtData': self.jwtData,
282
338
  'pumperId': self.pumperId,
283
339
  'accountId': self.accountId,
@@ -4,13 +4,15 @@ import arrow
4
4
  import logging
5
5
  import traceback
6
6
  import pkg_resources
7
+ import collections
7
8
  from datetime import datetime
8
9
  from pprint import pformat as pformat_base
9
10
 
10
11
  from .nightscout import NightscoutApi
11
12
  from .parser.nightscout import BASAL_EVENTTYPE, BOLUS_EVENTTYPE
12
13
  from .parser.tconnect import TConnectEntry
13
- from .sync.basal import process_ciq_basal_events
14
+ from .domain.tandemsource.event_class import EventClass
15
+ from .sync.tandemsource.choose_device import ChooseDevice
14
16
 
15
17
  try:
16
18
  __version__ = pkg_resources.require("tconnectsync")[0].version
@@ -51,27 +53,29 @@ def check_login(tconnect, time_start, time_end, verbose=False, sanitize=True):
51
53
 
52
54
  log("Loading secrets...")
53
55
  try:
54
- from .secret import TCONNECT_EMAIL, TCONNECT_PASSWORD, PUMP_SERIAL_NUMBER, NS_URL, NS_SECRET, TIMEZONE_NAME
56
+ from .secret import TCONNECT_EMAIL, TCONNECT_PASSWORD, TCONNECT_REGION, PUMP_SERIAL_NUMBER, NS_URL, NS_SECRET, TIMEZONE_NAME
57
+ from . import secret
55
58
  except ImportError as e:
56
59
  log("Error: Unable to load config file. Please check your .env file or environment variables")
57
60
  log_err(e)
58
-
61
+
62
+ log(f"Using {TCONNECT_REGION=}")
63
+
59
64
  if not TCONNECT_EMAIL or TCONNECT_EMAIL == 'email@email.com':
60
65
  log("Error: You have not specified a TCONNECT_EMAIL")
61
66
  errors += 1
62
-
67
+
63
68
  if not TCONNECT_PASSWORD or TCONNECT_PASSWORD == 'password':
64
69
  log("Error: You have not specified a TCONNECT_PASSWORD")
65
70
  errors += 1
66
-
71
+
67
72
  if not PUMP_SERIAL_NUMBER or PUMP_SERIAL_NUMBER == '11111111':
68
- log("Error: You have not specified a PUMP_SERIAL_NUMBER")
69
- errors += 1
70
-
73
+ log("Warning: You have not specified a PUMP_SERIAL_NUMBER, so the pump with most recent activity will be automatically used.")
74
+
71
75
  if not NS_URL or NS_URL == 'https://yournightscouturl/':
72
76
  log("Error: You have not specified a NS_URL")
73
77
  errors += 1
74
-
78
+
75
79
  if not NS_SECRET or NS_SECRET == 'apisecret':
76
80
  log("Error: You have not specified a NS_SECRET")
77
81
  errors += 1
@@ -80,89 +84,62 @@ def check_login(tconnect, time_start, time_end, verbose=False, sanitize=True):
80
84
 
81
85
  log("-----")
82
86
 
83
- log("Logging in to t:connect ControlIQ API...")
84
- try:
85
- summary = tconnect.controliq.dashboard_summary(time_start, time_end)
86
- debug("ControlIQ dashboard summary: \n%s" % pformat(summary))
87
- log("tconnect_software_ver: %s" % tconnect.controliq.tconnect_software_ver)
88
- except Exception as e:
89
- log("Error occurred querying ControlIQ API for dashboard_summary:")
90
- log_err(e)
91
- if e and "HTTP 404" in str(e):
92
- log("<!> The API returns a 404 error if there is no data for the provided dates (currently %s - %s). Try re-running with an earlier start date using --start-date and --end-date arguments." % (time_start, time_end))
93
- errors += 1
94
-
95
- log("Querying ControlIQ therapy_timeline...")
96
- lastBasalTime = None
97
- lastBasalDuration = None
87
+ serialNumberToPump = None
98
88
  try:
99
- tt = tconnect.controliq.therapy_timeline(time_start, time_end)
100
- debug("ControlIQ therapy_timeline: \n%s" % pformat(tt))
101
- if tt:
102
- processed_tt = process_ciq_basal_events(tt)
103
- debug("ControlIQ processed therapy_timeline: \n%s" % pformat(processed_tt))
104
- if processed_tt:
105
- log("Last ControlIQ processed therapy_timeline event: \n%s" % pformat(processed_tt[-1]))
106
- lastBasalTime = processed_tt[-1]['time']
107
- lastBasalDuration = processed_tt[-1]['duration_mins']
108
- except Exception as e:
109
- log("Error occurred querying ControlIQ therapy_timeline:")
110
- log_err(e)
111
- errors += 1
112
-
113
- log("Querying ControlIQ therapy_events...")
114
- try:
115
- androidevents = tconnect.controliq.therapy_events(time_start, time_end)
116
- debug("controliq therapy_events: \n%s" % pformat(androidevents))
117
- except Exception as e:
118
- log("Error occurred querying ControlIQ therapy_events:")
119
- log_err(e)
120
- errors += 1
121
-
122
- log("-----")
89
+ log("Fetching pump metadata...")
90
+ pumpEventMetadata = tconnect.tandemsource.pump_event_metadata()
123
91
 
124
- log("Initializing t:connect WS2 API...")
125
- ws2_loggedin = False
126
- try:
127
- summary = tconnect.ws2.basaliqtech(time_start, time_end)
128
- debug("WS2 basaliq status: \n%s" % pformat(summary))
129
- ws2_loggedin = True
130
- except Exception as e:
131
- log("Error occurred querying WS2 API. This is okay so long as you are not using the PUMP_EVENTS or IOB sync features.")
132
- log_err(e)
133
- errors += 1
134
-
135
- lastReadingTime = None
136
- if ws2_loggedin:
137
- log("Querying WS2 therapy_timeline_csv...")
138
- try:
139
- ttcsv = tconnect.ws2.therapy_timeline_csv(time_start, time_end)
140
- debug("therapy_timeline_csv: \n%s" % pformat(ttcsv))
141
- if ttcsv and "readingData" in ttcsv and len(ttcsv["readingData"]) > 0:
142
- log("Last therapy_timeline_csv reading: \n%s" % pformat(ttcsv["readingData"][-1]))
143
- lastReadingTime = TConnectEntry._datetime_parse(ttcsv["readingData"][-1]['EventDateTime'])
144
- except Exception as e:
145
- log("Error occurred querying WS2 therapy_timeline_csv. This is okay so long as you are not using the PUMP_EVENTS or IOB sync features.")
146
- log_err(e)
147
- errors += 1
148
- else:
149
- log("Not able to log in to WS2 API, so skipping therapy_timeline_csv")
150
-
151
- log("-----")
92
+ serialNumberToPump = {p['serialNumber']: p for p in pumpEventMetadata}
93
+ log(f'Found {len(serialNumberToPump)} pumps: {serialNumberToPump.keys()}')
94
+ for pumpSerial, pumpDetails in serialNumberToPump.items():
95
+ log(f'Pump {pumpSerial=}: {pumpDetails=}')
152
96
 
153
- log("Logging in to t:connect Android API...")
154
- summary = None
155
- try:
156
- summary = tconnect.android.user_profile()
157
- debug("Android user profile: \n%s" % pformat(summary))
97
+ log("Running ChooseDevice...")
98
+ tconnectDevice = ChooseDevice(secret, tconnect).choose()
99
+
100
+ log(f'ChooseDevice selected: {tconnectDevice}')
101
+
102
+ tconnectDeviceId = tconnectDevice['tconnectDeviceId']
103
+
104
+ log(f'Fetching pump events for {tconnectDeviceId=} {time_start=} {time_end=} fetch_all_event_types=False')
105
+
106
+ events = tconnect.tandemsource.pump_events(tconnectDeviceId, time_start, time_end, fetch_all_event_types=False)
107
+ events = list(events)
108
+
109
+ log(f"Found raw events count: {len(events)}")
158
110
 
159
- event = tconnect.android.last_event_uploaded(PUMP_SERIAL_NUMBER)
160
- debug("Android last uploaded event: \n%s" % pformat(event))
111
+
112
+ events_first_time = None
113
+ events_last_time = None
114
+ last_event_seqnum = None
115
+ for_eventclass = collections.defaultdict(list)
116
+ for event in events:
117
+ if not events_first_time:
118
+ events_first_time = event.eventTimestamp
119
+ if not events_last_time:
120
+ events_last_time = event.eventTimestamp
121
+ if not last_event_seqnum:
122
+ last_event_seqnum = event.seqNum
123
+ events_first_time = min(events_first_time, event.eventTimestamp)
124
+ events_last_time = max(events_last_time, event.eventTimestamp)
125
+ last_event_seqnum = max(event.seqNum, last_event_seqnum)
126
+
127
+ clazz = EventClass.for_event(event)
128
+ if clazz:
129
+ for_eventclass[clazz.name].append(event)
130
+
131
+ count_by_eventclass = {k: len(v) for k,v in for_eventclass.items()}
132
+ log(f"Found events count: {count_by_eventclass}")
133
+
134
+ log(f"Found first event time: {events_first_time}")
135
+ log(f"Found last event time: {events_last_time}")
136
+ log(f"Found last event sequence number: {last_event_seqnum}")
161
137
  except Exception as e:
162
- log("Error occurred querying Android API:")
138
+ log("Error occurred querying Tandem Source:")
163
139
  log_err(e)
164
140
  errors += 1
165
-
141
+
142
+
166
143
  log("-----")
167
144
 
168
145
  log("Logging in to Nightscout...")
@@ -186,17 +163,13 @@ def check_login(tconnect, time_start, time_end, verbose=False, sanitize=True):
186
163
  def time_ago(t):
187
164
  return '%s ago' % (arrow.now() - arrow.get(t)) if t else 'n/a'
188
165
 
189
- log("Last basal start time: %s (%s)" % (lastBasalTime, time_ago(lastBasalTime)))
190
- log("Last basal duration: %s" % lastBasalDuration)
191
- log("Last reading time: %s (%s)" % (lastReadingTime, time_ago(lastReadingTime)))
192
166
 
193
- log("-----")
194
167
 
195
168
  if errors == 0:
196
169
  log("No API errors returned!")
197
170
  else:
198
171
  log("API errors occurred. Please check the errors above.")
199
-
172
+
200
173
 
201
174
  with open('tconnectsync-check-output.log', 'w') as f:
202
175
 
@@ -208,14 +181,10 @@ def check_login(tconnect, time_start, time_end, verbose=False, sanitize=True):
208
181
  'NS_URL': NS_URL,
209
182
  'NS_SECRET': NS_SECRET
210
183
  }
211
-
212
- if summary:
213
- sanitizedData.update({
214
- 'ANDROID_PROFILE_USERID': summary.get('userID'),
215
- 'ANDROID_PROFILE_PATIENT_FULLNAME': summary.get('patientFullName'),
216
- 'ANDROID_PROFILE_CAREGIVER_FULLNAME': summary.get('caregiverFullName')
217
- })
218
-
184
+ if serialNumberToPump:
185
+ for i, (pumpSerial, pumpDetails) in enumerate(serialNumberToPump.items()):
186
+ sanitizedData[f'PUMP_SERIAL_{i}'] = pumpSerial
187
+ sanitizedData[f'TCONNECT_DEVICE_ID_{i}'] = pumpDetails['tconnectDeviceId']
219
188
  loglines = [run_sanitize(i, sanitizedData) for i in loglines]
220
189
 
221
190
  f.writelines(loglines)
@@ -41,6 +41,7 @@ def get_bool(name, default):
41
41
 
42
42
  TCONNECT_EMAIL = get('TCONNECT_EMAIL', 'email@email.com')
43
43
  TCONNECT_PASSWORD = get('TCONNECT_PASSWORD', 'password')
44
+ TCONNECT_REGION = get_one_of('TCONNECT_REGION', 'US', ['US', 'EU'])
44
45
 
45
46
  PUMP_SERIAL_NUMBER = int(get_number('PUMP_SERIAL_NUMBER', '11111111'))
46
47
 
@@ -27,11 +27,11 @@ class TandemSourceAutoupdate:
27
27
  until stopped (ctrl+c), or a maximum of AUTOUPDATE_MAX_LOOP_INVOCATIONS times.
28
28
  Stops if AUTOUPDATE_RESTART_ON_FAILURE is set and an error occurs.
29
29
  """
30
- def process(self, tconnect, nightscout, time_start, time_end, pretend, features=None):
30
+ def process(self, tconnect, nightscout, pretend, features=None):
31
31
  if features is None:
32
32
  features = DEFAULT_FEATURES
33
33
 
34
- # Read from android api, find exact interval to cut down on API calls
34
+ # Query for data, find exact interval to cut down on API calls
35
35
  # Refresh API token. If failure, die, have wrapper script re-run.
36
36
 
37
37
  self.autoupdate_start = time.time()
@@ -40,6 +40,9 @@ class TandemSourceAutoupdate:
40
40
  logger.debug("autoupdate loop")
41
41
  now = time.time()
42
42
 
43
+ time_end = datetime.datetime.now()
44
+ time_start = time_end - datetime.timedelta(days=1)
45
+
43
46
  tconnectDevice = ChooseDevice(self.secret, tconnect).choose()
44
47
 
45
48
  event_seqnum = None
@@ -10,8 +10,8 @@ import logging
10
10
 
11
11
  logger = logging.getLogger(__name__)
12
12
 
13
- def fetch_oneshot(username, password, time_start=None, time_end=None):
14
- tconnect = TConnectApi(username, password)
13
+ def fetch_oneshot(username, password, time_start=None, time_end=None, region='US'):
14
+ tconnect = TConnectApi(username, password, region)
15
15
  if not time_start and not time_end:
16
16
  time_end = datetime.datetime.now()
17
17
  time_start = time_end - datetime.timedelta(days=1)
@@ -16,5 +16,5 @@ Returns a TConnectApi object with default secret parameters.
16
16
  """
17
17
  def get_api():
18
18
  from ..api import TConnectApi
19
- from ..secret import TCONNECT_EMAIL, TCONNECT_PASSWORD
20
- return TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD)
19
+ from ..secret import TCONNECT_EMAIL, TCONNECT_PASSWORD, TCONNECT_REGION
20
+ return TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD, TCONNECT_REGION)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tconnectsync
3
- Version: 2.2.4
3
+ Version: 2.3.1
4
4
  Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
5
5
  Home-page: https://github.com/jwoglom/tconnectsync
6
6
  Author: James Woglom
@@ -120,6 +120,9 @@ You should specify the following parameters:
120
120
  TCONNECT_EMAIL='email@email.com'
121
121
  TCONNECT_PASSWORD='password'
122
122
 
123
+ # OPTIONAL: Your region (US or EU)
124
+ TCONNECT_REGION=US
125
+
123
126
  # URL of your Nightscout site
124
127
  NS_URL='https://yournightscouturl/'
125
128
  # Your Nightscout API_SECRET value
@@ -130,6 +133,7 @@ TIMEZONE_NAME='America/New_York'
130
133
 
131
134
  # OPTIONAL: Your pump's serial number (numeric)
132
135
  PUMP_SERIAL_NUMBER=11111111
136
+
133
137
  ```
134
138
 
135
139
  This file contains your t:connect username and password, Tandem pump serial number (which is utilized in API calls to t:connect), your Nightscout URL and secret token (for uploading data to Nightscout), and local timezone (the timezone used in t:connect). When specifying the timezone, enter a [TZ database name value](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
@@ -5,7 +5,6 @@ setup.cfg
5
5
  setup.py
6
6
  ./tconnectsync/__init__.py
7
7
  ./tconnectsync/__main__.py
8
- ./tconnectsync/autoupdate.py
9
8
  ./tconnectsync/check.py
10
9
  ./tconnectsync/features.py
11
10
  ./tconnectsync/nightscout.py
@@ -39,12 +38,6 @@ setup.py
39
38
  ./tconnectsync/parser/nightscout.py
40
39
  ./tconnectsync/parser/tconnect.py
41
40
  ./tconnectsync/sync/__init__.py
42
- ./tconnectsync/sync/basal.py
43
- ./tconnectsync/sync/bolus.py
44
- ./tconnectsync/sync/cgm.py
45
- ./tconnectsync/sync/iob.py
46
- ./tconnectsync/sync/profile.py
47
- ./tconnectsync/sync/pump_events.py
48
41
  ./tconnectsync/sync/tandemsource/__init__.py
49
42
  ./tconnectsync/sync/tandemsource/autoupdate.py
50
43
  ./tconnectsync/sync/tandemsource/choose_device.py
@@ -69,7 +62,6 @@ setup.py
69
62
  ./tconnectsync/util/constants.py
70
63
  tconnectsync/__init__.py
71
64
  tconnectsync/__main__.py
72
- tconnectsync/autoupdate.py
73
65
  tconnectsync/check.py
74
66
  tconnectsync/features.py
75
67
  tconnectsync/nightscout.py
@@ -109,12 +101,6 @@ tconnectsync/parser/ciq_therapy_events.py
109
101
  tconnectsync/parser/nightscout.py
110
102
  tconnectsync/parser/tconnect.py
111
103
  tconnectsync/sync/__init__.py
112
- tconnectsync/sync/basal.py
113
- tconnectsync/sync/bolus.py
114
- tconnectsync/sync/cgm.py
115
- tconnectsync/sync/iob.py
116
- tconnectsync/sync/profile.py
117
- tconnectsync/sync/pump_events.py
118
104
  tconnectsync/sync/tandemsource/__init__.py
119
105
  tconnectsync/sync/tandemsource/autoupdate.py
120
106
  tconnectsync/sync/tandemsource/choose_device.py
@@ -137,6 +123,4 @@ tconnectsync/sync/tandemsource/update_profiles.py
137
123
  tconnectsync/util/__init__.py
138
124
  tconnectsync/util/cli.py
139
125
  tconnectsync/util/constants.py
140
- tests/test_autoupdate.py
141
- tests/test_process.py
142
126
  tests/test_secret.py