tconnectsync 2.2.2__tar.gz → 2.3.0__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-2.2.2/tconnectsync.egg-info → tconnectsync-2.3.0}/PKG-INFO +7 -2
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/README.md +4 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/setup.cfg +1 -1
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/__init__.py +9 -7
- tconnectsync-2.3.0/tconnectsync/__main__.py +4 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/__init__.py +4 -3
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/tandemsource.py +70 -14
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/check.py +67 -98
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/build_events.py +18 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/events.py +693 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/raw_event.py +8 -1
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/secret.py +3 -2
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/autoupdate.py +1 -1
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/choose_device.py +14 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/cli_helpers.py +2 -2
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process.py +5 -3
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_device_status.py +1 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/util/cli.py +2 -2
- {tconnectsync-2.2.2 → tconnectsync-2.3.0/tconnectsync.egg-info}/PKG-INFO +7 -2
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync.egg-info/SOURCES.txt +2 -16
- tconnectsync-2.2.2/tconnectsync/autoupdate.py +0 -207
- tconnectsync-2.2.2/tconnectsync/sync/basal.py +0 -161
- tconnectsync-2.2.2/tconnectsync/sync/bolus.py +0 -120
- tconnectsync-2.2.2/tconnectsync/sync/cgm.py +0 -69
- tconnectsync-2.2.2/tconnectsync/sync/iob.py +0 -59
- tconnectsync-2.2.2/tconnectsync/sync/profile.py +0 -200
- tconnectsync-2.2.2/tconnectsync/sync/pump_events.py +0 -218
- tconnectsync-2.2.2/tests/test_autoupdate.py +0 -368
- tconnectsync-2.2.2/tests/test_process.py +0 -978
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/LICENSE.md +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/pyproject.toml +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/setup.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/android.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/common.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/controliq.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/webui.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/api/ws2.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/bolus.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/device_settings.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/tandemsource/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/tandemsource/event_class.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/tandemsource/pump_settings.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/therapy_event.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/domain/utility.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/generic.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/static_dicts.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/transforms.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/eventparser/utils.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/features.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/nightscout.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/parser/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/parser/ciq_therapy_events.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/parser/nightscout.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/parser/tconnect.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/process.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/helpers.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/heroku_helpers.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_alarm.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_basal.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_basal_resume.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_basal_suspension.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_bolus.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_cartridge.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_cgm_alert.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_cgm_reading.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/process_user_mode.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/sync/tandemsource/update_profiles.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/util/__init__.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync/util/constants.py +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync.egg-info/dependency_links.txt +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync.egg-info/entry_points.txt +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync.egg-info/requires.txt +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tconnectsync.egg-info/top_level.txt +0 -0
- {tconnectsync-2.2.2 → tconnectsync-2.3.0}/tests/test_secret.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: tconnectsync
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
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
|
|
@@ -27,6 +27,7 @@ Requires-Dist: cryptography
|
|
|
27
27
|
Requires-Dist: dataclasses-json
|
|
28
28
|
Requires-Dist: cffi
|
|
29
29
|
Requires-Dist: typing-extensions
|
|
30
|
+
Dynamic: license-file
|
|
30
31
|
|
|
31
32
|
# tconnectsync
|
|
32
33
|
|
|
@@ -119,6 +120,9 @@ You should specify the following parameters:
|
|
|
119
120
|
TCONNECT_EMAIL='email@email.com'
|
|
120
121
|
TCONNECT_PASSWORD='password'
|
|
121
122
|
|
|
123
|
+
# OPTIONAL: Your region (US or EU)
|
|
124
|
+
TCONNECT_REGION=US
|
|
125
|
+
|
|
122
126
|
# URL of your Nightscout site
|
|
123
127
|
NS_URL='https://yournightscouturl/'
|
|
124
128
|
# Your Nightscout API_SECRET value
|
|
@@ -129,6 +133,7 @@ TIMEZONE_NAME='America/New_York'
|
|
|
129
133
|
|
|
130
134
|
# OPTIONAL: Your pump's serial number (numeric)
|
|
131
135
|
PUMP_SERIAL_NUMBER=11111111
|
|
136
|
+
|
|
132
137
|
```
|
|
133
138
|
|
|
134
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).
|
|
@@ -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=
|
|
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
|
-
|
|
106
|
-
|
|
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:
|
|
@@ -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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 =
|
|
123
|
+
redirect_uri = self._region_urls['REDIRECT_URI']
|
|
74
124
|
scope = 'openid profile email'
|
|
75
125
|
|
|
76
|
-
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 =
|
|
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 .
|
|
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("
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
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
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
'
|
|
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)
|
|
@@ -68,6 +68,15 @@ class {name}(BaseEvent):
|
|
|
68
68
|
def eventId(self):
|
|
69
69
|
return self.ID
|
|
70
70
|
|
|
71
|
+
def todict(self):
|
|
72
|
+
return dict(
|
|
73
|
+
id=self.ID,
|
|
74
|
+
name=self.NAME,
|
|
75
|
+
seqNum=self.seqNum,
|
|
76
|
+
eventTimestamp=str(self.eventTimestamp),
|
|
77
|
+
{fields_dict}
|
|
78
|
+
)
|
|
79
|
+
|
|
71
80
|
'''
|
|
72
81
|
|
|
73
82
|
def firstLower(text):
|
|
@@ -97,6 +106,14 @@ def build_fields(event_def):
|
|
|
97
106
|
return '\n'.join([f'{" "*4}{f}' for f in ret])
|
|
98
107
|
|
|
99
108
|
|
|
109
|
+
def build_fields_dict(event_def):
|
|
110
|
+
ret = []
|
|
111
|
+
for name, field in event_def["data"].items():
|
|
112
|
+
suffix = 'Raw' if "transform" in field and name[-3:] != 'Raw' else ''
|
|
113
|
+
f = f'{fieldNameFormat(name)}{suffix}=self.{fieldNameFormat(name)}{suffix},'
|
|
114
|
+
ret.append(f)
|
|
115
|
+
return '\n'.join([f'{" "*12}{f}' for f in ret])
|
|
116
|
+
|
|
100
117
|
|
|
101
118
|
def build_decode(event_def):
|
|
102
119
|
p1s = []
|
|
@@ -134,6 +151,7 @@ def build_event(event_id, event_def):
|
|
|
134
151
|
return TEMPLATE.format(
|
|
135
152
|
name = eventNameFormat(event_def["name"]),
|
|
136
153
|
fields = build_fields(event_def),
|
|
154
|
+
fields_dict = build_fields_dict(event_def),
|
|
137
155
|
build_p1 = build_decode(event_def)[0],
|
|
138
156
|
build_p2 = build_decode(event_def)[1],
|
|
139
157
|
transform_funcs = build_transform_funcs(event_def),
|