tconnectsync 2.3.4__tar.gz → 3.0.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 (78) hide show
  1. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/PKG-INFO +42 -12
  2. tconnectsync-2.3.4/tconnectsync.egg-info/PKG-INFO → tconnectsync-3.0.1/README.md +36 -39
  3. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/setup.cfg +13 -4
  4. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/__init__.py +5 -4
  5. tconnectsync-3.0.1/tconnectsync/api/__init__.py +30 -0
  6. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/api/common.py +1 -1
  7. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/api/tandemsource.py +334 -82
  8. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/check.py +16 -10
  9. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/domain/tandemsource/event_class.py +4 -4
  10. tconnectsync-3.0.1/tconnectsync/domain/tandemsource/pump_settings.py +57 -0
  11. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/build_events.py +48 -1
  12. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/events.py +2090 -979
  13. tconnectsync-3.0.1/tconnectsync/eventparser/generic.py +41 -0
  14. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/raw_event.py +16 -0
  15. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/static_dicts.py +13 -2
  16. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/transforms.py +30 -4
  17. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/nightscout.py +33 -75
  18. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/parser/nightscout.py +19 -84
  19. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/secret.py +5 -0
  20. tconnectsync-3.0.1/tconnectsync/sync/tandemsource/autoupdate.py +297 -0
  21. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/choose_device.py +28 -12
  22. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/cli_helpers.py +2 -2
  23. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process.py +26 -9
  24. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_alarm.py +24 -10
  25. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_basal.py +19 -9
  26. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_basal_resume.py +15 -6
  27. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_basal_suspension.py +16 -7
  28. tconnectsync-3.0.1/tconnectsync/sync/tandemsource/process_bolus.py +133 -0
  29. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_cartridge.py +21 -10
  30. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_cgm_alert.py +28 -12
  31. tconnectsync-3.0.1/tconnectsync/sync/tandemsource/process_cgm_reading.py +132 -0
  32. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +35 -11
  33. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_device_status.py +28 -9
  34. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/process_user_mode.py +49 -36
  35. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/update_profiles.py +15 -11
  36. tconnectsync-2.3.4/README.md → tconnectsync-3.0.1/tconnectsync.egg-info/PKG-INFO +69 -8
  37. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync.egg-info/SOURCES.txt +2 -22
  38. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync.egg-info/requires.txt +10 -2
  39. tconnectsync-3.0.1/tests/test_eu_region_integration.py +320 -0
  40. tconnectsync-3.0.1/tests/test_nightscout.py +68 -0
  41. tconnectsync-2.3.4/tconnectsync/api/__init__.py +0 -80
  42. tconnectsync-2.3.4/tconnectsync/api/android.py +0 -175
  43. tconnectsync-2.3.4/tconnectsync/api/controliq.py +0 -206
  44. tconnectsync-2.3.4/tconnectsync/api/webui.py +0 -296
  45. tconnectsync-2.3.4/tconnectsync/api/ws2.py +0 -174
  46. tconnectsync-2.3.4/tconnectsync/domain/bolus.py +0 -25
  47. tconnectsync-2.3.4/tconnectsync/domain/device_settings.py +0 -44
  48. tconnectsync-2.3.4/tconnectsync/domain/tandemsource/pump_settings.py +0 -55
  49. tconnectsync-2.3.4/tconnectsync/domain/therapy_event.py +0 -483
  50. tconnectsync-2.3.4/tconnectsync/domain/utility.py +0 -24
  51. tconnectsync-2.3.4/tconnectsync/eventparser/generic.py +0 -21
  52. tconnectsync-2.3.4/tconnectsync/parser/ciq_therapy_events.py +0 -27
  53. tconnectsync-2.3.4/tconnectsync/parser/tconnect.py +0 -221
  54. tconnectsync-2.3.4/tconnectsync/process.py +0 -202
  55. tconnectsync-2.3.4/tconnectsync/sync/tandemsource/autoupdate.py +0 -183
  56. tconnectsync-2.3.4/tconnectsync/sync/tandemsource/process_bolus.py +0 -112
  57. tconnectsync-2.3.4/tconnectsync/sync/tandemsource/process_cgm_reading.py +0 -78
  58. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/LICENSE.md +0 -0
  59. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/pyproject.toml +0 -0
  60. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/setup.py +0 -0
  61. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/__main__.py +0 -0
  62. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/domain/__init__.py +0 -0
  63. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/domain/tandemsource/__init__.py +0 -0
  64. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/__init__.py +0 -0
  65. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/eventparser/utils.py +0 -0
  66. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/features.py +0 -0
  67. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/parser/__init__.py +0 -0
  68. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/__init__.py +0 -0
  69. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/__init__.py +0 -0
  70. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/helpers.py +0 -0
  71. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/sync/tandemsource/heroku_helpers.py +0 -0
  72. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/util/__init__.py +0 -0
  73. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/util/cli.py +0 -0
  74. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync/util/constants.py +0 -0
  75. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync.egg-info/dependency_links.txt +0 -0
  76. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync.egg-info/entry_points.txt +0 -0
  77. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tconnectsync.egg-info/top_level.txt +0 -0
  78. {tconnectsync-2.3.4 → tconnectsync-3.0.1}/tests/test_secret.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tconnectsync
3
- Version: 2.3.4
4
- Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
3
+ Version: 3.0.1
4
+ Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2 and Tandem Mobi
5
5
  Home-page: https://github.com/jwoglom/tconnectsync
6
6
  Author: James Woglom
7
7
  Author-email: j@wogloms.net
@@ -22,11 +22,13 @@ Requires-Dist: pysocks
22
22
  Requires-Dist: urllib3
23
23
  Requires-Dist: requests
24
24
  Requires-Dist: requests-oidc
25
- Requires-Dist: PyJWT
26
- Requires-Dist: cryptography
25
+ Requires-Dist: PyJWT==2.8.0
26
+ Requires-Dist: cryptography==43.0.1; python_version < "3.9"
27
+ Requires-Dist: cryptography; python_version >= "3.9"
27
28
  Requires-Dist: dataclasses-json
28
29
  Requires-Dist: cffi
29
30
  Requires-Dist: typing-extensions
31
+ Requires-Dist: importlib-metadata; python_version < "3.8"
30
32
  Dynamic: license-file
31
33
 
32
34
  # tconnectsync
@@ -412,6 +414,36 @@ An example `run.sh` if you built tconnectsync locally:
412
414
  docker run tconnectsync --auto-update
413
415
  ```
414
416
 
417
+ #### Tuning Auto-Update
418
+
419
+ These optional environment variables control how `--auto-update` polls and how
420
+ it behaves when things go wrong. The defaults are sensible; you generally only
421
+ need these if you are seeing too many (or too few) restarts.
422
+
423
+ | Variable | Default | What it does |
424
+ | --- | --- | --- |
425
+ | `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` | `300` | Poll interval when no better estimate is available. Also the ceiling for the retry backoff below. |
426
+ | `AUTOUPDATE_MAX_SLEEP_SECONDS` | `1500` | Upper bound on the adaptive poll interval, regardless of how rarely new data appears. |
427
+ | `AUTOUPDATE_UNEXPECTED_NO_INDEX_SLEEP_SECONDS` | `60` | How long to wait when new data is overdue based on the pump's previous cadence. |
428
+ | `AUTOUPDATE_USE_FIXED_SLEEP` | `false` | Set true to always sleep `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` instead of adapting to the pump's observed upload cadence. |
429
+ | `AUTOUPDATE_API_FAILURE_MINUTES` | `45` | Exit with a non-zero code after this many minutes of unbroken API/network failure, so your container platform restarts tconnectsync and can alert you. Set `0` to never exit. |
430
+ | `AUTOUPDATE_NO_DATA_FAILURE_MINUTES` | `180` | Log an error if the pump has not reported new events for this long. Usually means the pump simply is not uploading. |
431
+ | `AUTOUPDATE_FAILURE_MINUTES` | `75` | Log an error if events are appearing but no data has synced successfully for this long. |
432
+ | `AUTOUPDATE_RESTART_ON_FAILURE` | `false` | Whether the two watchdogs above also exit non-zero. Independent of `AUTOUPDATE_API_FAILURE_MINUTES`. |
433
+ | `AUTOUPDATE_MAX_LOOP_INVOCATIONS` | `-1` | Stop after this many poll cycles. `-1` means run forever; mainly useful for testing. |
434
+
435
+ **On failures and restarts.** Transient errors (DNS blips, timeouts, HTTP 404/502/503
436
+ from Tandem) do not crash tconnectsync. It retries with a growing backoff — 30s,
437
+ 60s, 120s, 240s, then holding at `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` — and resets
438
+ as soon as a poll succeeds. Staying in-process matters: an exit discards the
439
+ cached credentials, so a restart loop means a fresh login on every attempt,
440
+ which risks tripping Tandem's rate limiting.
441
+
442
+ Only once the API has been failing continuously for `AUTOUPDATE_API_FAILURE_MINUTES`
443
+ does tconnectsync give up and exit, so that a genuine outage surfaces (roughly one
444
+ restart per hour) instead of disappearing into an endless quiet retry. Invalid
445
+ credentials are never retried — they exit immediately, since retrying cannot help.
446
+
415
447
  ### Running with Cron
416
448
 
417
449
  If you choose not to run tconnectsync with `--auto-update` continuously,
@@ -450,13 +482,11 @@ If main.py doesn't exist in `C:\Users\<USERNAME>\AppData\Local\Programs\Python\<
450
482
 
451
483
  ## Tandem APIs
452
484
 
453
- This application utilizes three separate Tandem APIs for obtaining t:connect data, referenced here by the identifying part of their URLs:
485
+ As of version 2.0, tconnectsync retrieves all of its data from a single Tandem API, [**tandemsource**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/tandemsource.py), which powers [Tandem Source](https://source.tandemdiabetes.com/). After logging in, tconnectsync fetches the list of pumps on the account along with a stream of raw pump event data, which is decoded locally (see [`tconnectsync/eventparser`](https://github.com/jwoglom/tconnectsync/tree/master/tconnectsync/eventparser)) to extract basal, bolus, CGM, and other pump events.
454
486
 
455
- * [**controliq**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/controliq.py) - Contains Control:IQ related data, namely a timeline of all Basal events uploaded by the pump, separated by type (temp basals, algorithmically-updated basals, or profile-updated basals). Additionally includes CGM and Bolus data.
456
- * [**android**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/android.py) - Used internally by the t:connect Android app, these API endpoints were discovered by reverse-engineering the Android app. Most of the API endpoints are used for uploading pump data, and tconnectsync uses one endpoint which returns the most recent event ID uploaded by the pump, so we know when more data has been uploaded.
457
- * [**tconnectws2**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/ws2.py) - More legacy than the others, this seems to power the bulk of the main t:connect website. It is used as a last resort due to severe performance issues with this API (see https://github.com/jwoglom/tconnectsync/issues/43). We can use it to retrieve a CSV export of non-ControlIQ basal data, as well as bolus and IOB data. It is only used for bolus data as a fallback, and for pump-reported IOB data if requested. Full tracking of pump events also uses a limited version of this API.
487
+ > Earlier versions of tconnectsync (1.x) instead used three separate legacy t:connect APIs (`controliq`, `android`, and `tconnectws2`). Those APIs — and the code supporting them — were removed once t:connect was shut down in favor of Tandem Source.
458
488
 
459
- I have only tested tconnectsync with a Tandem pump set in the US Eastern timezone. Tandem's (to us, undocumented) APIs are [a bit loose with timezones](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/parser.py#L15), so please let me know if you notice any timezone-related bugs.
489
+ I have only tested tconnectsync with a Tandem pump set in the US Eastern timezone. Tandem's (to us, undocumented) APIs are a bit loose with timezones, so please let me know if you notice any timezone-related bugs.
460
490
  ## Backfilling t:connect Data
461
491
 
462
492
  To backfill existing t:connect data in to Nightscout, you can use the `--start-date` and `--end-date` options. For example, the following will upload all t:connect data between January 1st and March 1st, 2020 to Nightscout:
@@ -469,14 +499,14 @@ In order to bulk-import a lot of data, you may need to use shorter intervals, an
469
499
 
470
500
  One oddity when backfilling data is that the Control:IQ specific API endpoints return errors if they are queried before you updated your pump to utilize Control:IQ. This is [partially worked around in tconnectsync's code](https://github.com/jwoglom/tconnectsync/blob/d841c3811aeff3671d941a7d3ff4b80cce6a219e/main.py#L238), but you might need to update the logic if you did not switch to a Control:IQ enabled pump immediately after launch.
471
501
 
472
- ## t:connect API Testing
502
+ ## Tandem Source API Testing
473
503
 
474
- To test t:connect API endpoints in a Python shell, you can do something like the following:
504
+ To test Tandem Source API endpoints in a Python shell, you can do something like the following:
475
505
 
476
506
  ```python
477
507
  import tconnectsync
478
508
  tconnectsync.util.cli.enable_logging()
479
509
  api = tconnectsync.util.cli.get_api()
480
510
  # Make API calls, e.g.
481
- therapy_timeline = api.controliq.therapy_timeline('2022-08-01', '2022-08-10')
511
+ pumps = api.tandemsource.pump_event_metadata()
482
512
  ```
@@ -1,34 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: tconnectsync
3
- Version: 2.3.4
4
- Summary: Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
5
- Home-page: https://github.com/jwoglom/tconnectsync
6
- Author: James Woglom
7
- Author-email: j@wogloms.net
8
- Project-URL: Bug Tracker, https://github.com/jwoglom/tconnectsync/issues
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.7
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE.md
15
- Requires-Dist: requests
16
- Requires-Dist: bs4
17
- Requires-Dist: arrow
18
- Requires-Dist: lxml
19
- Requires-Dist: python-dotenv
20
- Requires-Dist: requests-mock
21
- Requires-Dist: pysocks
22
- Requires-Dist: urllib3
23
- Requires-Dist: requests
24
- Requires-Dist: requests-oidc
25
- Requires-Dist: PyJWT
26
- Requires-Dist: cryptography
27
- Requires-Dist: dataclasses-json
28
- Requires-Dist: cffi
29
- Requires-Dist: typing-extensions
30
- Dynamic: license-file
31
-
32
1
  # tconnectsync
33
2
 
34
3
  ![Python Package workflow](https://github.com/jwoglom/tconnectsync/actions/workflows/python-package.yml/badge.svg)
@@ -412,6 +381,36 @@ An example `run.sh` if you built tconnectsync locally:
412
381
  docker run tconnectsync --auto-update
413
382
  ```
414
383
 
384
+ #### Tuning Auto-Update
385
+
386
+ These optional environment variables control how `--auto-update` polls and how
387
+ it behaves when things go wrong. The defaults are sensible; you generally only
388
+ need these if you are seeing too many (or too few) restarts.
389
+
390
+ | Variable | Default | What it does |
391
+ | --- | --- | --- |
392
+ | `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` | `300` | Poll interval when no better estimate is available. Also the ceiling for the retry backoff below. |
393
+ | `AUTOUPDATE_MAX_SLEEP_SECONDS` | `1500` | Upper bound on the adaptive poll interval, regardless of how rarely new data appears. |
394
+ | `AUTOUPDATE_UNEXPECTED_NO_INDEX_SLEEP_SECONDS` | `60` | How long to wait when new data is overdue based on the pump's previous cadence. |
395
+ | `AUTOUPDATE_USE_FIXED_SLEEP` | `false` | Set true to always sleep `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` instead of adapting to the pump's observed upload cadence. |
396
+ | `AUTOUPDATE_API_FAILURE_MINUTES` | `45` | Exit with a non-zero code after this many minutes of unbroken API/network failure, so your container platform restarts tconnectsync and can alert you. Set `0` to never exit. |
397
+ | `AUTOUPDATE_NO_DATA_FAILURE_MINUTES` | `180` | Log an error if the pump has not reported new events for this long. Usually means the pump simply is not uploading. |
398
+ | `AUTOUPDATE_FAILURE_MINUTES` | `75` | Log an error if events are appearing but no data has synced successfully for this long. |
399
+ | `AUTOUPDATE_RESTART_ON_FAILURE` | `false` | Whether the two watchdogs above also exit non-zero. Independent of `AUTOUPDATE_API_FAILURE_MINUTES`. |
400
+ | `AUTOUPDATE_MAX_LOOP_INVOCATIONS` | `-1` | Stop after this many poll cycles. `-1` means run forever; mainly useful for testing. |
401
+
402
+ **On failures and restarts.** Transient errors (DNS blips, timeouts, HTTP 404/502/503
403
+ from Tandem) do not crash tconnectsync. It retries with a growing backoff — 30s,
404
+ 60s, 120s, 240s, then holding at `AUTOUPDATE_DEFAULT_SLEEP_SECONDS` — and resets
405
+ as soon as a poll succeeds. Staying in-process matters: an exit discards the
406
+ cached credentials, so a restart loop means a fresh login on every attempt,
407
+ which risks tripping Tandem's rate limiting.
408
+
409
+ Only once the API has been failing continuously for `AUTOUPDATE_API_FAILURE_MINUTES`
410
+ does tconnectsync give up and exit, so that a genuine outage surfaces (roughly one
411
+ restart per hour) instead of disappearing into an endless quiet retry. Invalid
412
+ credentials are never retried — they exit immediately, since retrying cannot help.
413
+
415
414
  ### Running with Cron
416
415
 
417
416
  If you choose not to run tconnectsync with `--auto-update` continuously,
@@ -450,13 +449,11 @@ If main.py doesn't exist in `C:\Users\<USERNAME>\AppData\Local\Programs\Python\<
450
449
 
451
450
  ## Tandem APIs
452
451
 
453
- This application utilizes three separate Tandem APIs for obtaining t:connect data, referenced here by the identifying part of their URLs:
452
+ As of version 2.0, tconnectsync retrieves all of its data from a single Tandem API, [**tandemsource**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/tandemsource.py), which powers [Tandem Source](https://source.tandemdiabetes.com/). After logging in, tconnectsync fetches the list of pumps on the account along with a stream of raw pump event data, which is decoded locally (see [`tconnectsync/eventparser`](https://github.com/jwoglom/tconnectsync/tree/master/tconnectsync/eventparser)) to extract basal, bolus, CGM, and other pump events.
454
453
 
455
- * [**controliq**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/controliq.py) - Contains Control:IQ related data, namely a timeline of all Basal events uploaded by the pump, separated by type (temp basals, algorithmically-updated basals, or profile-updated basals). Additionally includes CGM and Bolus data.
456
- * [**android**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/android.py) - Used internally by the t:connect Android app, these API endpoints were discovered by reverse-engineering the Android app. Most of the API endpoints are used for uploading pump data, and tconnectsync uses one endpoint which returns the most recent event ID uploaded by the pump, so we know when more data has been uploaded.
457
- * [**tconnectws2**](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/api/ws2.py) - More legacy than the others, this seems to power the bulk of the main t:connect website. It is used as a last resort due to severe performance issues with this API (see https://github.com/jwoglom/tconnectsync/issues/43). We can use it to retrieve a CSV export of non-ControlIQ basal data, as well as bolus and IOB data. It is only used for bolus data as a fallback, and for pump-reported IOB data if requested. Full tracking of pump events also uses a limited version of this API.
454
+ > Earlier versions of tconnectsync (1.x) instead used three separate legacy t:connect APIs (`controliq`, `android`, and `tconnectws2`). Those APIs — and the code supporting them — were removed once t:connect was shut down in favor of Tandem Source.
458
455
 
459
- I have only tested tconnectsync with a Tandem pump set in the US Eastern timezone. Tandem's (to us, undocumented) APIs are [a bit loose with timezones](https://github.com/jwoglom/tconnectsync/blob/master/tconnectsync/parser.py#L15), so please let me know if you notice any timezone-related bugs.
456
+ I have only tested tconnectsync with a Tandem pump set in the US Eastern timezone. Tandem's (to us, undocumented) APIs are a bit loose with timezones, so please let me know if you notice any timezone-related bugs.
460
457
  ## Backfilling t:connect Data
461
458
 
462
459
  To backfill existing t:connect data in to Nightscout, you can use the `--start-date` and `--end-date` options. For example, the following will upload all t:connect data between January 1st and March 1st, 2020 to Nightscout:
@@ -469,14 +466,14 @@ In order to bulk-import a lot of data, you may need to use shorter intervals, an
469
466
 
470
467
  One oddity when backfilling data is that the Control:IQ specific API endpoints return errors if they are queried before you updated your pump to utilize Control:IQ. This is [partially worked around in tconnectsync's code](https://github.com/jwoglom/tconnectsync/blob/d841c3811aeff3671d941a7d3ff4b80cce6a219e/main.py#L238), but you might need to update the logic if you did not switch to a Control:IQ enabled pump immediately after launch.
471
468
 
472
- ## t:connect API Testing
469
+ ## Tandem Source API Testing
473
470
 
474
- To test t:connect API endpoints in a Python shell, you can do something like the following:
471
+ To test Tandem Source API endpoints in a Python shell, you can do something like the following:
475
472
 
476
473
  ```python
477
474
  import tconnectsync
478
475
  tconnectsync.util.cli.enable_logging()
479
476
  api = tconnectsync.util.cli.get_api()
480
477
  # Make API calls, e.g.
481
- therapy_timeline = api.controliq.therapy_timeline('2022-08-01', '2022-08-10')
478
+ pumps = api.tandemsource.pump_event_metadata()
482
479
  ```
@@ -1,9 +1,9 @@
1
1
  [metadata]
2
2
  name = tconnectsync
3
- version = 2.3.4
3
+ version = 3.0.1
4
4
  author = James Woglom
5
5
  author_email = j@wogloms.net
6
- description = Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2
6
+ description = Syncs Tandem Source (formerly t:connect) insulin pump data to Nightscout for the t:slim X2 and Tandem Mobi
7
7
  long_description = file: README.md
8
8
  long_description_content_type = text/markdown
9
9
  url = https://github.com/jwoglom/tconnectsync
@@ -30,11 +30,13 @@ install_requires =
30
30
  urllib3
31
31
  requests
32
32
  requests-oidc
33
- PyJWT
34
- cryptography
33
+ PyJWT==2.8.0
34
+ cryptography==43.0.1; python_version < "3.9"
35
+ cryptography; python_version >= "3.9"
35
36
  dataclasses-json
36
37
  cffi
37
38
  typing-extensions
39
+ importlib-metadata; python_version < "3.8"
38
40
 
39
41
  [options.packages.find]
40
42
  where = .
@@ -46,6 +48,13 @@ exclude =
46
48
  console_scripts =
47
49
  tconnectsync = tconnectsync:main
48
50
 
51
+ [mypy]
52
+ files =
53
+ tconnectsync
54
+ follow_imports = silent
55
+ ignore_missing_imports = True
56
+ disable_error_code = import-untyped
57
+
49
58
  [egg_info]
50
59
  tag_build =
51
60
  tag_date = 0
@@ -3,13 +3,15 @@ import datetime
3
3
  import arrow
4
4
  import argparse
5
5
  import logging
6
- import pkg_resources
7
6
  import typing
8
7
 
9
8
  # Required for cryptography lib in python 3.7
10
9
  if sys.version_info < (3, 8):
11
10
  import typing_extensions
12
11
  typing.Protocol = typing_extensions.Protocol
12
+ from importlib_metadata import PackageNotFoundError, version
13
+ else:
14
+ from importlib.metadata import PackageNotFoundError, version
13
15
 
14
16
  from .api import TConnectApi
15
17
  from .sync.tandemsource.autoupdate import TandemSourceAutoupdate
@@ -37,8 +39,8 @@ except Exception as e:
37
39
 
38
40
 
39
41
  try:
40
- __version__ = pkg_resources.require("tconnectsync")[0].version
41
- except Exception:
42
+ __version__ = version("tconnectsync")
43
+ except PackageNotFoundError:
42
44
  __version__ = "UNKNOWN"
43
45
 
44
46
  def parse_args(*args, **kwargs):
@@ -126,4 +128,3 @@ def main(*args, **kwargs):
126
128
 
127
129
  # return exit code 0 if processed events
128
130
  sys.exit(0 if added>0 else 1)
129
-
@@ -0,0 +1,30 @@
1
+ import logging
2
+
3
+ from .tandemsource import TandemSourceApi
4
+ from .. import secret
5
+
6
+ logger = logging.getLogger(__name__)
7
+
8
+ """A wrapper for the Tandem Source API."""
9
+ class TConnectApi:
10
+ email = None
11
+ password = None
12
+
13
+ def __init__(self, email, password, region=None):
14
+ self.email = email
15
+ self.password = password
16
+ # A caller which does not pass a region (e.g. tconnectsync-heroku)
17
+ # must get the configured TCONNECT_REGION, not a hardcoded US
18
+ # default which would send EU accounts to the US endpoints (#152).
19
+ self.region = region or secret.TCONNECT_REGION
20
+ self._tandemsource = None
21
+
22
+ @property
23
+ def tandemsource(self):
24
+ if self._tandemsource and not self._tandemsource.needs_relogin():
25
+ return self._tandemsource
26
+
27
+ logger.debug(f"Instantiating new TandemSourceApi for region {self.region}")
28
+
29
+ self._tandemsource = TandemSourceApi(self.email, self.password, self.region)
30
+ return self._tandemsource
@@ -112,7 +112,7 @@ def days_between(start, end) -> int:
112
112
  return diff.days
113
113
 
114
114
  # both inclusive
115
- def split_days_range(start_a, end_a, days: int = 5) -> List[Tuple[str, str]]:
115
+ def split_days_range(start_a, end_a, days: int = 5) -> List[Tuple[arrow.Arrow, arrow.Arrow]]:
116
116
  ranges = []
117
117
  start = arrow.get(start_a)
118
118
  end = arrow.get(end_a)