tconnectsync 0.9.7__tar.gz → 2.0.2__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 (77) hide show
  1. {tconnectsync-0.9.7/tconnectsync.egg-info → tconnectsync-2.0.2}/PKG-INFO +29 -34
  2. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/README.md +28 -33
  3. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/setup.cfg +1 -1
  4. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/__init__.py +25 -10
  5. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/__init__.py +12 -0
  6. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/android.py +10 -4
  7. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/common.py +7 -2
  8. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/controliq.py +26 -4
  9. tconnectsync-2.0.2/tconnectsync/api/tandemsource.py +378 -0
  10. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/autoupdate.py +9 -9
  11. tconnectsync-2.0.2/tconnectsync/domain/tandemsource/event_class.py +39 -0
  12. tconnectsync-2.0.2/tconnectsync/domain/tandemsource/pump_settings.py +52 -0
  13. tconnectsync-2.0.2/tconnectsync/eventparser/build_events.py +172 -0
  14. tconnectsync-2.0.2/tconnectsync/eventparser/events.py +4388 -0
  15. tconnectsync-2.0.2/tconnectsync/eventparser/generic.py +15 -0
  16. tconnectsync-2.0.2/tconnectsync/eventparser/raw_event.py +35 -0
  17. tconnectsync-2.0.2/tconnectsync/eventparser/static_dicts.py +144 -0
  18. tconnectsync-2.0.2/tconnectsync/eventparser/transforms.py +121 -0
  19. tconnectsync-2.0.2/tconnectsync/eventparser/utils.py +23 -0
  20. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/features.py +7 -4
  21. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/nightscout.py +47 -28
  22. tconnectsync-2.0.2/tconnectsync/parser/__init__.py +0 -0
  23. tconnectsync-2.0.2/tconnectsync/parser/nightscout.py +325 -0
  24. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/secret.py +6 -0
  25. tconnectsync-2.0.2/tconnectsync/sync/__init__.py +0 -0
  26. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/__init__.py +0 -0
  27. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/autoupdate.py +170 -0
  28. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/choose_device.py +48 -0
  29. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/helpers.py +8 -0
  30. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process.py +96 -0
  31. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_alarm.py +73 -0
  32. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_basal.py +86 -0
  33. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_basal_resume.py +66 -0
  34. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_basal_suspension.py +67 -0
  35. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_bolus.py +112 -0
  36. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_cartridge.py +100 -0
  37. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_cgm_alert.py +92 -0
  38. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_cgm_reading.py +76 -0
  39. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +96 -0
  40. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/process_user_mode.py +244 -0
  41. tconnectsync-2.0.2/tconnectsync/sync/tandemsource/update_profiles.py +210 -0
  42. {tconnectsync-0.9.7 → tconnectsync-2.0.2/tconnectsync.egg-info}/PKG-INFO +29 -34
  43. tconnectsync-2.0.2/tconnectsync.egg-info/SOURCES.txt +134 -0
  44. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tests/test_process.py +15 -15
  45. tconnectsync-0.9.7/tconnectsync/parser/nightscout.py +0 -184
  46. tconnectsync-0.9.7/tconnectsync.egg-info/SOURCES.txt +0 -46
  47. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/LICENSE.md +0 -0
  48. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/pyproject.toml +0 -0
  49. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/setup.py +0 -0
  50. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/webui.py +0 -0
  51. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/api/ws2.py +0 -0
  52. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/check.py +0 -0
  53. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/domain/__init__.py +0 -0
  54. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/domain/bolus.py +0 -0
  55. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/domain/device_settings.py +0 -0
  56. {tconnectsync-0.9.7/tconnectsync/parser → tconnectsync-2.0.2/tconnectsync/domain/tandemsource}/__init__.py +0 -0
  57. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/domain/therapy_event.py +0 -0
  58. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/domain/utility.py +0 -0
  59. {tconnectsync-0.9.7/tconnectsync/sync → tconnectsync-2.0.2/tconnectsync/eventparser}/__init__.py +0 -0
  60. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/parser/ciq_therapy_events.py +0 -0
  61. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/parser/tconnect.py +0 -0
  62. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/process.py +0 -0
  63. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/basal.py +0 -0
  64. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/bolus.py +0 -0
  65. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/cgm.py +0 -0
  66. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/iob.py +0 -0
  67. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/profile.py +0 -0
  68. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/sync/pump_events.py +0 -0
  69. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/util/__init__.py +0 -0
  70. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/util/cli.py +0 -0
  71. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync/util/constants.py +0 -0
  72. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync.egg-info/dependency_links.txt +0 -0
  73. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync.egg-info/entry_points.txt +0 -0
  74. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync.egg-info/requires.txt +0 -0
  75. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tconnectsync.egg-info/top_level.txt +0 -0
  76. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tests/test_autoupdate.py +0 -0
  77. {tconnectsync-0.9.7 → tconnectsync-2.0.2}/tests/test_secret.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tconnectsync
3
- Version: 0.9.7
3
+ Version: 2.0.2
4
4
  Summary: Syncs Tandem t:connect pump data to Nightscout for the t:slim X2
5
5
  Home-page: https://github.com/jwoglom/tconnectsync
6
6
  Author: James Woglom
@@ -23,29 +23,29 @@ Requires-Dist: python-dotenv
23
23
  ![Python Package workflow](https://github.com/jwoglom/tconnectsync/actions/workflows/python-package.yml/badge.svg)
24
24
  [![codecov](https://codecov.io/gh/jwoglom/tconnectsync/branch/master/graph/badge.svg)](https://codecov.io/gh/jwoglom/tconnectsync)
25
25
 
26
- Tconnectsync synchronizes data one-way from the Tandem Diabetes t:connect web/mobile application to Nightscout.
26
+ Tconnectsync synchronizes data one-way from Tandem Source to Nightscout.
27
+
28
+ > [!IMPORTANT]
29
+ > Tandem has announced that t:connect will be shut down in favor of Tandem Source in the US beginning September 30, 2024.
30
+ > tconnectsync has undergone major changes to support Tandem Source. **For Tandem Source support, you MUST upgrade to tconnectsync version 2.0 or above.**
27
31
 
28
32
  If you have a t:slim X2 pump with the companion t:connect mobile Android or iOS app, this will allow your pump bolus and basal data to be uploaded to [Nightscout](https://github.com/nightscout/cgm-remote-monitor) automatically.
29
33
  Together with a CGM uploader, such as [xDrip+](https://github.com/NightscoutFoundation/xDrip) or the official Dexcom mobile app plus Dexcom Share, this allows your CGM _and_ pump data to be automatically uploaded to Nightscout!
30
34
 
31
- If you have an Android phone, you can use [tconnectpatcher](https://github.com/jwoglom/tconnectpatcher) to modify the t:connect Android app to upload more frequently. By default, pump data is uploaded to Tandem's servers every hour, but with tconnectpatcher the frequency can be brought down to **as low as every five minutes**! This allows for nearly real-time (albeit not fully instantaneous) pump data updates, almost like your pump uploads data directly to Nightscout!
32
35
 
33
36
  ## How It Works
34
37
 
35
- At a high level, tconnectsync works by querying Tandem's undocumented APIs to receive basal and bolus data from t:connect, and then uploads that data as treatment objects to Nightscout. It contains features for checking for new Tandem pump data continuously, and updating that data along with the pump's reported IOB value to Nightscout whenever there is new data.
38
+ At a high level, tconnectsync works by querying Tandem's undocumented APIs to receive basal and bolus data from Tandem Source, and then uploads that data as treatment objects to Nightscout. It contains features for checking for new Tandem pump data continuously, and updating that data to Nightscout whenever there is new data.
36
39
 
37
40
  When you run the program with no arguments, it performs a single cycle of the following, and exits after completion:
38
41
 
39
- * Queries for basal information via the t:connect ControlIQ API.
40
- * Queries for bolus, basal, and IOB data via the t:connect non-ControlIQ API.
41
- * Merges the basal information received from the two APIs. (If using ControlIQ, then basal information appears only on the ControlIQ API. If not using ControlIQ, it appears only on the legacy API.)
42
- * Queries Nightscout for the most recently created Temp Basal object by tconnectsync, and uploads all data newer than that.
43
- * Queries Nightscout for the most recently created Bolus object by tconnectsync, and uploads all data newer than that.
44
-
45
- If run with the `--auto-update` flag, then the application performs the following steps:
42
+ * Logs in to Tandem Source
43
+ * Fetches your list of pumps, and unless overridden by an environment variable, fetches the event data for the pump which was most recently used
44
+ * Processes the internal pump event metadata to extract basal, bolus, CGM, and other pump event data
45
+ * Queries Nightscout to find the most recent data which was uploaded to it for each event category
46
+ * Uploads any missing data to Nightscout
46
47
 
47
- * Queries an API endpoint used only by the t:connect mobile app which returns an internal event ID, corresponding to the most recent event published by the mobile app.
48
- * Whenever the internal event ID changes (denoting that the mobile app uploaded new data to synchronize), perform all of the above mentioned steps to synchronize data.
48
+ If run with the `--auto-update` flag, then the application periodically looks for new data and synchronizes it to Nightscout in a loop every few minutes.
49
49
 
50
50
  ## What Gets Synced
51
51
 
@@ -56,28 +56,23 @@ When setting up tconnectsync, you can choose to configure which synchronization
56
56
  Here are a few examples of reasons why you might want to adjust the enabled synchronization features:
57
57
 
58
58
  * If you currently input boluses into Nightscout manually with comments, then you may wish to _disable the `BOLUS` synchronization feature_ so that there are no duplicated boluses in Nightscout.
59
- * If you want to see Sleep and Exercise Mode data appear in Nightscout, then you may with to _enable the `PUMP_EVENTS` synchronization feature_.
60
- * If you want to automatically update your Nightscout insulin profile settings from your pump, then you may want to _enable the `PROFILES` synchronization feature_.
59
+ * If you want to see Sleep and Exercise Mode data appear in Nightscout, then you may wish to _enable the `PUMP_EVENTS` synchronization feature_.
60
+ * If you want to automatically update your Nightscout insulin profile settings from your pump, then you may wish to _enable the `PROFILES` synchronization feature_.
61
61
 
62
62
  These synchronization features are enabled by default:
63
63
 
64
64
  * `BASAL`: Basal data
65
65
  * `BOLUS`: Bolus data
66
+ * `PUMP_EVENTS`: Events reported by the pump. Includes support for the following:
67
+ * Alarms, like cartridge out-of-insulin or pump malfunction
68
+ * Basal suspension (user or pump-initiated) and resume
69
+ * Cartridge, cannula, and tubing filled
70
+ * Sleep and exercise modes
71
+ * `PROFILES`: Insulin profile information, including segments, basal rates, correction factors, carb ratios, and the profile which is active.
66
72
 
67
73
  The following synchronization features can be optionally enabled:
74
+ * `CGM`: Adds Dexcom CGM readings from the pump to Nightscout as SGV (sensor glucose value) entries. This should only be used in a situation where xDrip/Dexcom Share/etc. is not used and the pump connection to the CGM will be the only source of CGM data to Nightscout. **THIS WILL DELIVER CGM DATA WITH A SIGNIFICANT (>30 MINUTE) LAG AND SHOULD NOT BE USED AS A REPLACEMENT FOR DEXCOM SHARE OR OTHER REAL TIME MONITORING.**
68
75
 
69
- * `PROFILES`: Insulin profile information, including segments, basal rates, correction factors, carb ratios, and the profile which is active.
70
- * `PUMP_EVENTS`: Events reported by the pump. Includes support for the following:
71
- * Site/Cartridge Change (occurs for both a site change and a cartridge change)
72
- * Empty Cartridge/Pump Shutdown (from my investigation, occurs either when the cartridge runs out of insulin OR you hard-shut off the pump)
73
- * User Suspended (occurs when you manually disable insulin delivery)
74
- * Exercise Mode (in Nightscout, appears with a start and end time)
75
- * Sleep Mode (in Nightscout, appears with a start and end time)
76
- * `IOB`: Insulin-on-board data. Only the most recent IOB entry is saved to Nightscout, as an "activity". The Nightscout UI does not currently display this information. In order to read this value, you need to query the Nightscout activity API endpoint. If you don't know what that means, then there is no reason to enable this option.
77
-
78
- The following synchronization features are considered to be in alpha, and haven't been widely tested. If you want to use them, [set `ENABLE_TESTING_MODES=true` for them to show up](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/features.py#L29):
79
- * `BOLUS_BG`: Adds BG readings which are associated with boluses on the pump into the Nightscout treatment object. It will determine whether the BG reading was automatically filled via the Dexcom connection on the pump or was manually entered by seeing if the BG reading matches the current CGM reading as known to the pump at that time. Support for this is nearly complete.
80
- * `CGM`: Adds Dexcom CGM readings from the pump to Nightscout as SGV (sensor glucose value) entries. This should only be used in a situation where xDrip/Dexcom Share/etc. is not used and the pump connection to the CGM will be the only source of CGM data to Nightscout. This requires additional testing before it should be considered ready.
81
76
 
82
77
  To specify custom synchronization features, pass the names of the desired features to the `--features` flag, e.g.:
83
78
 
@@ -114,9 +109,6 @@ You should specify the following parameters:
114
109
  TCONNECT_EMAIL='email@email.com'
115
110
  TCONNECT_PASSWORD='password'
116
111
 
117
- # Your pump's serial number (numeric)
118
- PUMP_SERIAL_NUMBER=11111111
119
-
120
112
  # URL of your Nightscout site
121
113
  NS_URL='https://yournightscouturl/'
122
114
  # Your Nightscout API_SECRET value
@@ -124,6 +116,9 @@ NS_SECRET='apisecret'
124
116
 
125
117
  # Current timezone of the pump
126
118
  TIMEZONE_NAME='America/New_York'
119
+
120
+ # OPTIONAL: Your pump's serial number (numeric)
121
+ PUMP_SERIAL_NUMBER=11111111
127
122
  ```
128
123
 
129
124
  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).
@@ -139,10 +134,10 @@ First, ensure that you have **Python 3** with **Pip** installed:
139
134
  * **On MacOS:** Open Terminal. Install [Homebrew](https://brew.sh/), and then run `brew install python3`
140
135
  * **On Linux:** Follow your distribution's specific instructions.
141
136
  - For Debian/Ubuntu based distros, `sudo apt install python3 python3-pip`
142
- - For CentOS/Rocky Linux 8:
137
+ - For CentOS/Rocky Linux 8:
143
138
  - `sudo dnf install python39-pip`
144
- - `sudo alternatives --set python /usr/bin/python3.9`
145
- * **On Windows:**
139
+ - `sudo alternatives --set python /usr/bin/python3.9`
140
+ * **On Windows:**
146
141
  - **With WSL:** Install Ubuntu under the [Windows Subsystem for Linux](https://ubuntu.com/wsl).
147
142
  Open the Ubuntu Terminal, then run `sudo apt install python3 python3-pip`.
148
143
  Perform the remainder of the steps under the Ubuntu environment.
@@ -424,7 +419,7 @@ An example of a user crontab `crontab -e` if not running system-wide, which runs
424
419
 
425
420
  You can use one of the same `run.sh` files referenced above, but remove the `--auto-update` flag since you are handling the functionality for running the script periodically yourself.
426
421
 
427
- ### For Native Windows
422
+ ### For Native Windows
428
423
 
429
424
  Create a batch file 'tconnectsync.bat' file containing:
430
425
 
@@ -3,29 +3,29 @@
3
3
  ![Python Package workflow](https://github.com/jwoglom/tconnectsync/actions/workflows/python-package.yml/badge.svg)
4
4
  [![codecov](https://codecov.io/gh/jwoglom/tconnectsync/branch/master/graph/badge.svg)](https://codecov.io/gh/jwoglom/tconnectsync)
5
5
 
6
- Tconnectsync synchronizes data one-way from the Tandem Diabetes t:connect web/mobile application to Nightscout.
6
+ Tconnectsync synchronizes data one-way from Tandem Source to Nightscout.
7
+
8
+ > [!IMPORTANT]
9
+ > Tandem has announced that t:connect will be shut down in favor of Tandem Source in the US beginning September 30, 2024.
10
+ > tconnectsync has undergone major changes to support Tandem Source. **For Tandem Source support, you MUST upgrade to tconnectsync version 2.0 or above.**
7
11
 
8
12
  If you have a t:slim X2 pump with the companion t:connect mobile Android or iOS app, this will allow your pump bolus and basal data to be uploaded to [Nightscout](https://github.com/nightscout/cgm-remote-monitor) automatically.
9
13
  Together with a CGM uploader, such as [xDrip+](https://github.com/NightscoutFoundation/xDrip) or the official Dexcom mobile app plus Dexcom Share, this allows your CGM _and_ pump data to be automatically uploaded to Nightscout!
10
14
 
11
- If you have an Android phone, you can use [tconnectpatcher](https://github.com/jwoglom/tconnectpatcher) to modify the t:connect Android app to upload more frequently. By default, pump data is uploaded to Tandem's servers every hour, but with tconnectpatcher the frequency can be brought down to **as low as every five minutes**! This allows for nearly real-time (albeit not fully instantaneous) pump data updates, almost like your pump uploads data directly to Nightscout!
12
15
 
13
16
  ## How It Works
14
17
 
15
- At a high level, tconnectsync works by querying Tandem's undocumented APIs to receive basal and bolus data from t:connect, and then uploads that data as treatment objects to Nightscout. It contains features for checking for new Tandem pump data continuously, and updating that data along with the pump's reported IOB value to Nightscout whenever there is new data.
18
+ At a high level, tconnectsync works by querying Tandem's undocumented APIs to receive basal and bolus data from Tandem Source, and then uploads that data as treatment objects to Nightscout. It contains features for checking for new Tandem pump data continuously, and updating that data to Nightscout whenever there is new data.
16
19
 
17
20
  When you run the program with no arguments, it performs a single cycle of the following, and exits after completion:
18
21
 
19
- * Queries for basal information via the t:connect ControlIQ API.
20
- * Queries for bolus, basal, and IOB data via the t:connect non-ControlIQ API.
21
- * Merges the basal information received from the two APIs. (If using ControlIQ, then basal information appears only on the ControlIQ API. If not using ControlIQ, it appears only on the legacy API.)
22
- * Queries Nightscout for the most recently created Temp Basal object by tconnectsync, and uploads all data newer than that.
23
- * Queries Nightscout for the most recently created Bolus object by tconnectsync, and uploads all data newer than that.
24
-
25
- If run with the `--auto-update` flag, then the application performs the following steps:
22
+ * Logs in to Tandem Source
23
+ * Fetches your list of pumps, and unless overridden by an environment variable, fetches the event data for the pump which was most recently used
24
+ * Processes the internal pump event metadata to extract basal, bolus, CGM, and other pump event data
25
+ * Queries Nightscout to find the most recent data which was uploaded to it for each event category
26
+ * Uploads any missing data to Nightscout
26
27
 
27
- * Queries an API endpoint used only by the t:connect mobile app which returns an internal event ID, corresponding to the most recent event published by the mobile app.
28
- * Whenever the internal event ID changes (denoting that the mobile app uploaded new data to synchronize), perform all of the above mentioned steps to synchronize data.
28
+ If run with the `--auto-update` flag, then the application periodically looks for new data and synchronizes it to Nightscout in a loop every few minutes.
29
29
 
30
30
  ## What Gets Synced
31
31
 
@@ -36,28 +36,23 @@ When setting up tconnectsync, you can choose to configure which synchronization
36
36
  Here are a few examples of reasons why you might want to adjust the enabled synchronization features:
37
37
 
38
38
  * If you currently input boluses into Nightscout manually with comments, then you may wish to _disable the `BOLUS` synchronization feature_ so that there are no duplicated boluses in Nightscout.
39
- * If you want to see Sleep and Exercise Mode data appear in Nightscout, then you may with to _enable the `PUMP_EVENTS` synchronization feature_.
40
- * If you want to automatically update your Nightscout insulin profile settings from your pump, then you may want to _enable the `PROFILES` synchronization feature_.
39
+ * If you want to see Sleep and Exercise Mode data appear in Nightscout, then you may wish to _enable the `PUMP_EVENTS` synchronization feature_.
40
+ * If you want to automatically update your Nightscout insulin profile settings from your pump, then you may wish to _enable the `PROFILES` synchronization feature_.
41
41
 
42
42
  These synchronization features are enabled by default:
43
43
 
44
44
  * `BASAL`: Basal data
45
45
  * `BOLUS`: Bolus data
46
+ * `PUMP_EVENTS`: Events reported by the pump. Includes support for the following:
47
+ * Alarms, like cartridge out-of-insulin or pump malfunction
48
+ * Basal suspension (user or pump-initiated) and resume
49
+ * Cartridge, cannula, and tubing filled
50
+ * Sleep and exercise modes
51
+ * `PROFILES`: Insulin profile information, including segments, basal rates, correction factors, carb ratios, and the profile which is active.
46
52
 
47
53
  The following synchronization features can be optionally enabled:
54
+ * `CGM`: Adds Dexcom CGM readings from the pump to Nightscout as SGV (sensor glucose value) entries. This should only be used in a situation where xDrip/Dexcom Share/etc. is not used and the pump connection to the CGM will be the only source of CGM data to Nightscout. **THIS WILL DELIVER CGM DATA WITH A SIGNIFICANT (>30 MINUTE) LAG AND SHOULD NOT BE USED AS A REPLACEMENT FOR DEXCOM SHARE OR OTHER REAL TIME MONITORING.**
48
55
 
49
- * `PROFILES`: Insulin profile information, including segments, basal rates, correction factors, carb ratios, and the profile which is active.
50
- * `PUMP_EVENTS`: Events reported by the pump. Includes support for the following:
51
- * Site/Cartridge Change (occurs for both a site change and a cartridge change)
52
- * Empty Cartridge/Pump Shutdown (from my investigation, occurs either when the cartridge runs out of insulin OR you hard-shut off the pump)
53
- * User Suspended (occurs when you manually disable insulin delivery)
54
- * Exercise Mode (in Nightscout, appears with a start and end time)
55
- * Sleep Mode (in Nightscout, appears with a start and end time)
56
- * `IOB`: Insulin-on-board data. Only the most recent IOB entry is saved to Nightscout, as an "activity". The Nightscout UI does not currently display this information. In order to read this value, you need to query the Nightscout activity API endpoint. If you don't know what that means, then there is no reason to enable this option.
57
-
58
- The following synchronization features are considered to be in alpha, and haven't been widely tested. If you want to use them, [set `ENABLE_TESTING_MODES=true` for them to show up](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/features.py#L29):
59
- * `BOLUS_BG`: Adds BG readings which are associated with boluses on the pump into the Nightscout treatment object. It will determine whether the BG reading was automatically filled via the Dexcom connection on the pump or was manually entered by seeing if the BG reading matches the current CGM reading as known to the pump at that time. Support for this is nearly complete.
60
- * `CGM`: Adds Dexcom CGM readings from the pump to Nightscout as SGV (sensor glucose value) entries. This should only be used in a situation where xDrip/Dexcom Share/etc. is not used and the pump connection to the CGM will be the only source of CGM data to Nightscout. This requires additional testing before it should be considered ready.
61
56
 
62
57
  To specify custom synchronization features, pass the names of the desired features to the `--features` flag, e.g.:
63
58
 
@@ -94,9 +89,6 @@ You should specify the following parameters:
94
89
  TCONNECT_EMAIL='email@email.com'
95
90
  TCONNECT_PASSWORD='password'
96
91
 
97
- # Your pump's serial number (numeric)
98
- PUMP_SERIAL_NUMBER=11111111
99
-
100
92
  # URL of your Nightscout site
101
93
  NS_URL='https://yournightscouturl/'
102
94
  # Your Nightscout API_SECRET value
@@ -104,6 +96,9 @@ NS_SECRET='apisecret'
104
96
 
105
97
  # Current timezone of the pump
106
98
  TIMEZONE_NAME='America/New_York'
99
+
100
+ # OPTIONAL: Your pump's serial number (numeric)
101
+ PUMP_SERIAL_NUMBER=11111111
107
102
  ```
108
103
 
109
104
  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).
@@ -119,10 +114,10 @@ First, ensure that you have **Python 3** with **Pip** installed:
119
114
  * **On MacOS:** Open Terminal. Install [Homebrew](https://brew.sh/), and then run `brew install python3`
120
115
  * **On Linux:** Follow your distribution's specific instructions.
121
116
  - For Debian/Ubuntu based distros, `sudo apt install python3 python3-pip`
122
- - For CentOS/Rocky Linux 8:
117
+ - For CentOS/Rocky Linux 8:
123
118
  - `sudo dnf install python39-pip`
124
- - `sudo alternatives --set python /usr/bin/python3.9`
125
- * **On Windows:**
119
+ - `sudo alternatives --set python /usr/bin/python3.9`
120
+ * **On Windows:**
126
121
  - **With WSL:** Install Ubuntu under the [Windows Subsystem for Linux](https://ubuntu.com/wsl).
127
122
  Open the Ubuntu Terminal, then run `sudo apt install python3 python3-pip`.
128
123
  Perform the remainder of the steps under the Ubuntu environment.
@@ -404,7 +399,7 @@ An example of a user crontab `crontab -e` if not running system-wide, which runs
404
399
 
405
400
  You can use one of the same `run.sh` files referenced above, but remove the `--auto-update` flag since you are handling the functionality for running the script periodically yourself.
406
401
 
407
- ### For Native Windows
402
+ ### For Native Windows
408
403
 
409
404
  Create a batch file 'tconnectsync.bat' file containing:
410
405
 
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = tconnectsync
3
- version = 0.9.7
3
+ version = 2.0.2
4
4
  author = James Woglom
5
5
  author_email = j@wogloms.net
6
6
  description = Syncs Tandem t:connect pump data to Nightscout for the t:slim X2
@@ -8,6 +8,9 @@ import pkg_resources
8
8
  from .api import TConnectApi
9
9
  from .process import process_time_range
10
10
  from .autoupdate import Autoupdate
11
+ from .sync.tandemsource.autoupdate import TandemSourceAutoupdate
12
+ from .sync.tandemsource.choose_device import ChooseDevice as TandemSourceChooseDevice
13
+ from .sync.tandemsource.process import ProcessTimeRange as TandemSourceProcessTimeRange
11
14
  from .check import check_login
12
15
  from .nightscout import NightscoutApi
13
16
  from .features import DEFAULT_FEATURES, ALL_FEATURES
@@ -19,7 +22,8 @@ try:
19
22
  NS_URL,
20
23
  NS_SECRET,
21
24
  NS_SKIP_TLS_VERIFY,
22
- PUMP_SERIAL_NUMBER
25
+ PUMP_SERIAL_NUMBER,
26
+ NS_IGNORE_CONN_ERRORS
23
27
  )
24
28
  from . import secret
25
29
  except Exception as e:
@@ -43,6 +47,7 @@ def parse_args(*args, **kwargs):
43
47
  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.')
44
48
  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.')
45
49
  parser.add_argument('--features', dest='features', nargs='+', default=DEFAULT_FEATURES, choices=ALL_FEATURES, help='Specifies what data should be synchronized between tconnect and Nightscout.')
50
+ parser.add_argument('--tandem-source', dest='tandem_source', action='store_const', const=True, default=False, help='FOR TESTING: Use Tandem Source')
46
51
 
47
52
  return parser.parse_args(*args, **kwargs)
48
53
 
@@ -82,23 +87,33 @@ def main(*args, **kwargs):
82
87
  if NS_URL == 'https://yournightscouturl/':
83
88
  logging.warn('NO NIGHTSCOUT URL WAS PROVIDED. Ensure your have set NS_URL appropriately.')
84
89
  if PUMP_SERIAL_NUMBER == '11111111':
85
- logging.warn('NO PUMP SERIAL NUMBER WAS PROVIDED. Ensure you have set PUMP_SERIAL_NUMBER appropriately.')
90
+ if args.tandem_source:
91
+ secret.PUMP_SERIAL_NUMBER = None
92
+ else:
93
+ logging.warn('NO PUMP SERIAL NUMBER WAS PROVIDED. Ensure you have set PUMP_SERIAL_NUMBER appropriately.')
86
94
 
87
95
  tconnect = TConnectApi(TCONNECT_EMAIL, TCONNECT_PASSWORD)
88
96
 
89
- nightscout = NightscoutApi(NS_URL, NS_SECRET, NS_SKIP_TLS_VERIFY)
97
+ nightscout = NightscoutApi(NS_URL, NS_SECRET, skip_verify=NS_SKIP_TLS_VERIFY, ignore_conn_errors=NS_IGNORE_CONN_ERRORS)
90
98
 
91
- if args.check_login:
92
- return check_login(tconnect, time_start, time_end)
99
+ # NOT YET MIGRATED
100
+ # if args.check_login:
101
+ # return check_login(tconnect, time_start, time_end)
102
+
103
+ logging.warning("THIS VERSION OF TCONNECTSYNC READS DATA FROM TANDEM SOURCE, AND MAY CONTAIN BUGS!")
104
+ logging.info("You may notice different behavior compared to older versions which utilized t:connect data sources.")
105
+ logging.info("To report a bug or to get help, see https://github.com/jwoglom/tconnectsync/issues")
93
106
 
94
107
  logging.info("Enabled features: " + ", ".join(args.features))
95
108
 
109
+ if args.check_login:
110
+ args.pretend = True
111
+
96
112
  if args.auto_update:
97
- print("Starting auto-update between", time_start, "and", time_end, "(PRETEND)" if args.pretend else "")
98
- u = Autoupdate(secret)
113
+ u = TandemSourceAutoupdate(secret)
99
114
  sys.exit(u.process(tconnect, nightscout, time_start, time_end, args.pretend, features=args.features))
100
115
  else:
101
- print("Processing data between", time_start, "and", time_end, "(PRETEND)" if args.pretend else "")
102
- added = process_time_range(tconnect, nightscout, time_start, time_end, args.pretend, features=args.features)
103
- print("Added", added, "items")
116
+ tconnectDevice = TandemSourceChooseDevice(secret, tconnect).choose()
117
+ added = TandemSourceProcessTimeRange(tconnect, nightscout, tconnectDevice, pretend=args.pretend, features=args.features).process(time_start, time_end)
118
+ sys.exit(added)
104
119
 
@@ -4,6 +4,7 @@ from .android import AndroidApi
4
4
  from .controliq import ControlIQApi
5
5
  from .ws2 import WS2Api
6
6
  from .webui import WebUIScraper
7
+ from .tandemsource import TandemSourceApi
7
8
 
8
9
  logger = logging.getLogger(__name__)
9
10
 
@@ -19,6 +20,17 @@ class TConnectApi:
19
20
  self._ws2 = None
20
21
  self._android = None
21
22
  self._webui = None
23
+ self._tandemsource = None
24
+
25
+ @property
26
+ def tandemsource(self):
27
+ if self._tandemsource and not self._tandemsource.needs_relogin():
28
+ return self._tandemsource
29
+
30
+ logger.debug("Instantiating new TandemSourceApi")
31
+
32
+ self._tandemsource = TandemSourceApi(self.email, self.password)
33
+ return self._tandemsource
22
34
 
23
35
 
24
36
  @property
@@ -29,6 +29,10 @@ class AndroidApi:
29
29
  ANDROID_API_USERNAME = base64.b64decode('QzIzMzFDRDYtRDQ1MC00OTVFLTlDMTktNjcyMTUyMzBDODVD').decode()
30
30
  ANDROID_API_PASSWORD = base64.b64decode('dHo0MzNLVzVRREM5VjdmIXo2QF4ybyZZNlNHR1lo').decode()
31
31
 
32
+ # These credentials are used by tconnect web
33
+ TCONNECT_WEB_USERNAME = base64.b64decode('M0U2MzU3QkEtRjYyNS00REQyLUI2NUYtNEI1RTgxNDRBQTZG').decode()
34
+ TCONNECT_WEB_PASSWORD = base64.b64decode('cUMyaXFIc2w3OFFoR0RYdCpMenFwb1pxZTl3eHN6').decode()
35
+
32
36
  ANDROID_USER_AGENT = 'Dalvik/2.1.0 (Linux; U; Android 12; Pixel 4a Build/SP2A.220305.012)'
33
37
 
34
38
  # These tokens are separate from the "standard" tdcservices API
@@ -65,15 +69,17 @@ class AndroidApi:
65
69
  raise ApiLoginException(r.status_code, 'Received HTTP %s during login: %s' % (r.status_code, r.text))
66
70
 
67
71
  j = r.json()
68
- if "user" not in j or not j["user"]:
69
- raise ApiException(r.status_code, 'No user details present in AndroidApi oauth response: %s' % r.text)
72
+ # tconnect web returns a null user
73
+ # if "user" not in j or not j["user"]:
74
+ # raise ApiException(r.status_code, 'No user details present in AndroidApi oauth response: %s' % r.text)
70
75
 
71
76
  self.accessToken = j["accessToken"]
72
77
  self.accessTokenExpiresAt = j["accessTokenExpiresAt"]
73
78
  # NOTE: the refresh token is currently unused, instead a new access
74
79
  # token is obtained from scratch by re-logging in when it expires.
75
- self.refreshToken = j["refreshToken"]
76
- self.refreshTokenExpiresAt = j["refreshTokenExpiresAt"]
80
+ if "refreshToken" in j and "refreshTokenExpiresAt" in j:
81
+ self.refreshToken = j["refreshToken"]
82
+ self.refreshTokenExpiresAt = j["refreshTokenExpiresAt"]
77
83
  self.userId = j["user"]["id"]
78
84
 
79
85
  logger.info("Logged in to AndroidApi successfully (expiration: %s, %s)" % (self.accessTokenExpiresAt, timeago(self.accessTokenExpiresAt)))
@@ -11,6 +11,11 @@ def parse_date(date):
11
11
  return date
12
12
  return (date or datetime.datetime.now()).strftime('%m-%d-%Y')
13
13
 
14
+ def parse_ymd_date(date):
15
+ if type(date) == str:
16
+ date = arrow.get(date)
17
+ return (date or datetime.datetime.now()).strftime('%Y-%m-%d')
18
+
14
19
  def parsed_date_to_arrow(date):
15
20
  return arrow.get(datetime.datetime.strptime(date, '%m-%d-%Y'))
16
21
 
@@ -117,11 +122,11 @@ def split_days_range(start_a, end_a, days: int = 5) -> List[Tuple[str, str]]:
117
122
  if (cur - cur_s).days >= days-1:
118
123
  ranges.append((cur_s, cur))
119
124
  cur_s = cur + datetime.timedelta(days=1)
120
-
125
+
121
126
  cur += datetime.timedelta(days=1)
122
127
  if len(ranges) > 0 and (end - ranges[-1][-1]).days > 0:
123
128
  ranges.append((cur_s, end))
124
-
129
+
125
130
  return ranges
126
131
 
127
132
  class ApiException(Exception):
@@ -14,7 +14,7 @@ class ControlIQApi:
14
14
  BASE_URL = 'https://tdcservices.tandemdiabetes.com/'
15
15
  LOGIN_URL = 'https://tconnect.tandemdiabetes.com/login.aspx?ReturnUrl=%2f'
16
16
 
17
- LAST_CONFIRMED_SOFTWARE_VERSION = 't:connect 7.16.0.1'
17
+ LAST_CONFIRMED_SOFTWARE_VERSION = 't:connect 7.17.2.3'
18
18
 
19
19
  userGuid = None
20
20
  accessToken = None
@@ -51,9 +51,21 @@ class ControlIQApi:
51
51
  raise ApiException(fwd.status_code, 'Error retrieving t:connect login cookies.')
52
52
 
53
53
  self.userGuid = req.cookies['UserGUID']
54
- self.accessToken = req.cookies['accessToken']
55
- self.accessTokenExpiresAt = req.cookies['accessTokenExpiresAt']
56
- logger.info("Logged in to ControlIQApi successfully (expiration: %s, %s)" % (self.accessTokenExpiresAt, timeago(self.accessTokenExpiresAt)))
54
+ if 'accessToken' in req.cookies and 'accessTokenExpiresAt' in req.cookies:
55
+ self.accessToken = req.cookies['accessToken']
56
+ self.accessTokenExpiresAt = req.cookies['accessTokenExpiresAt']
57
+ logger.info("Logged in to ControlIQApi successfully via accessToken cookie (expiration: %s, %s)" % (self.accessTokenExpiresAt, timeago(self.accessTokenExpiresAt)))
58
+ else:
59
+ logger.info("No accessToken cookie found when logging in to ControlIQApi. Triggering AndroidApi auth")
60
+
61
+ from .android import AndroidApi
62
+ android = AndroidApi(email, password)
63
+ self.accessToken = android.accessToken
64
+ self.accessTokenExpiresAt = android.accessTokenExpiresAt
65
+
66
+ logger.info("Logged in to AndroidApi successfully via accessToken param (expiration: %s, %s)" % (self.accessTokenExpiresAt, timeago(self.accessTokenExpiresAt)))
67
+
68
+
57
69
  self.loginSession = s
58
70
  return True
59
71
 
@@ -74,6 +86,13 @@ class ControlIQApi:
74
86
  contents = "%s[SNIP]%s" % (contents[:500], contents[-500:])
75
87
  logger.info("BeautifulSoup parsed contents: %s" % contents)
76
88
  pass
89
+ if not soup.select_one("#__VIEWSTATE"):
90
+ enc_contents = str(soup.encode_contents())
91
+ if "Web Page Blocked!" in enc_contents or "Attack ID:" in enc_contents:
92
+ logger.warn("Being ratelimited/blocked by web application firewall. Sleeping for 30 minutes before retrying.")
93
+ logger.info("BeautifulSoup parsed contents: %s" % enc_contents)
94
+ time.sleep(1800)
95
+ exit(1)
77
96
  return {
78
97
  "__LASTFOCUS": "",
79
98
  "__EVENTTARGET": "ctl00$ContentBody$LoginControl$linkLogin",
@@ -96,6 +115,9 @@ class ControlIQApi:
96
115
  return None
97
116
 
98
117
  def needs_relogin(self):
118
+ if not self.accessTokenExpiresAt:
119
+ return False
120
+
99
121
  diff = (arrow.get(self.accessTokenExpiresAt) - arrow.get())
100
122
  return (diff.seconds <= 5 * 60)
101
123