[AI-authored] Fix #146: migrate Tandem Source sync from reportsfacade to bff endpoints#149
Open
craigpress wants to merge 1 commit into
Open
[AI-authored] Fix #146: migrate Tandem Source sync from reportsfacade to bff endpoints#149craigpress wants to merge 1 commit into
craigpress wants to merge 1 commit into
Conversation
…om#146) Tandem retired the api/reports/reportsfacade/* endpoints on 2026-06-30, returning HTTP 404 and breaking all sync. They are replaced by api/reports/bff/* which return JSON instead of the legacy binary event blob. Changes: - api_headers(): send Origin/Referer = source.tandemdiabetes.com (the BFF WAF returns HTTP 403 for the old tconnect origin). - pump_event_metadata(): fetch api/reports/bff/pumper/{pumperId} and remap to the legacy per-pump dict shape, including a reconstructed lastUpload.settings (tDependentSegs <- timeDependentSegments) for profile sync. Filters to the active pump(s), since the BFF lists all historical pumps on the account. - pump_events_raw()/pump_events(): fetch api/reports/bff/pump-logs/{deviceId} and build native eventparser objects from the JSON. - eventparser/json_events.py (new): build eventparser dataclasses from BFF JSON by normalizing eventProperties keys to dataclass field names; event timestamps are reconstructed to match the binary path exactly. Tested against a live US-region account: all event classes (basal, bolus, CGM, suspend/resume, alarms, user-mode) parse; basal/bolus/profile values match the prior binary-path output; profile comparison reports "up to date". NOTE: This change was written by an AI (Claude) at a user's request and should receive human review before merging, as it handles insulin dosing data. Co-Authored-By: Claude <noreply@anthropic.com>
Owner
|
Hey @craigpress - can you please try the 'dev' branch, I have been iterating there throughout the evening to try and get the new API working, adding e2e tests as I go. |
Author
|
Testing now. I had my agent pull it and compare to my data and it worked. Having it install now. I use this to pull to nightscout and my own server and display in a custom app with advanced ai analytics and iOS notifications. I’m trying to build personal predictive models and be able to predict highs and lows with enough warning to be able to bolus to avoid prolonged highs.
…________________________________
From: James Woglom ***@***.***>
Sent: Wednesday, 01 July 2026 01:33:25
To: jwoglom/tconnectsync ***@***.***>
Cc: Craig Press ***@***.***>; Mention ***@***.***>
Subject: Re: [jwoglom/tconnectsync] [AI-authored] Fix #146: migrate Tandem Source sync from reportsfacade to bff endpoints (PR #149)
[https://avatars.githubusercontent.com/u/192620?s=20&v=4]jwoglom left a comment (jwoglom/tconnectsync#149)<#149 (comment)>
Hey @craigpress<https://github.com/craigpress> - can you please try the 'dev' branch, I have been iterating there throughout the evening to try and get the new API working, adding e2e tests as I go.
—
Reply to this email directly, view it on GitHub<#149?email_source=notifications&email_token=AFOKQF7DOW43IWFIKQ6M2YT5CSPCLA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBVGA2TOMJUGE32M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4850571417>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFOKQF5ZHTX7ZFVDNWB6BRT5CSPCLAVCNFSNUABFKJSXA33TNF2G64TZHMZDSMRRHA3DSMJYHNEXG43VMU5TINZYGIYDCMJQHAY2C5QC>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #146. Tandem retired the
api/reports/reportsfacade/*endpoints on 2026-06-30 (HTTP 404), breaking all Tandem Source sync. They are replaced byapi/reports/bff/*, which return JSON instead of the legacy binary event blob. This migrates the three affected calls.Important
This PR was written by an AI (Claude), at the request of a tconnectsync user whose child's pump sync broke. It has been tested against a live account (below) but should be reviewed carefully by a human before merging, since it handles insulin dosing data. You mentioned in #146 that you're already working on a fix — please treat this as a reference/starting point, not a rubber-stamp. Happy to adjust it however you'd like, or feel free to cherry-pick.
Changes
api_headers()— sendOrigin/Referer=source.tandemdiabetes.com. The BFF WAF returns HTTP 403 for the oldtconnect.tandemdiabetes.comorigin.pump_event_metadata()—GET api/reports/bff/pumper/{pumperId}, remapped to the legacy per-pump dict shape. The BFF lists every pump ever on the account (including entries with null / placeholder-future dates), so it filters to the pump(s) uploaded in the last 30 days. ReconstructslastUpload.settings(tDependentSegs←timeDependentSegments, plus the flattened CGM alert thresholds) soUpdateProfiles/PumpSettingskeep working unchanged.pump_events_raw()/pump_events()—GET api/reports/bff/pump-logs/{deviceId}?pumperId=&startDate=&endDate=&eventIds=(ISO-8601 datetimes), then build native eventparser objects from the JSON.eventparser/json_events.py(new) — generic JSON→eventparser builder. For eacheventCodeit looks up the eventparser dataclass and mapseventPropertieskeys to fields by normalizing names (strip a trailingRaw, lowercase); integer-bitmask arrays are folded to ints. Event timestamps are reconstructed frompumpDateTimeto land on the identical instant as the binary path. No unit conversion happens here — the downstream processors still do milliunit→unit,carbratio * 0.001, etc., unchanged.Why a generic builder
Rather than hand-map ~30 event classes, the builder derives each mapping from the dataclass via introspection. The JSON
eventPropertiesnames line up with the dataclass fields under the normalize rule (e.g.commandedRate→commandedRate,insulinDelivered→insulindelivered,bg→BG,completionStatus→completionstatusRaw,carbRatio→carbratioRaw). Unknown event codes fall back to a bareRawEvent, matching the binaryEvent().Testing
Tested against a live US-region account with
--pretend(no writes),--featurescovering everything + fetch-all-events:Read 1320 events from BFF pump-logs, classified as{BASAL: 555, CGM_READING: 557, CGM_ALERT: 11, USER_MODE: 4, BOLUS: 68, BASAL_SUSPENSION: 1, ALARM: 2, BASAL_RESUME: 1}.5.17U / 31g), and the full multi-segment profile decode to the same values the binary path produced;compare_profilesreports "up to date" against the profile tconnectsync had previously written from binary data.Processed 609 events, no traceback).Not covered (reviewer should check): EU region (no account to test), and extended/combo-bolus edge cases beyond those that appeared in the test window.
🤖 Generated with Claude Code