mirror of
https://github.com/jwoglom/tconnectsync.git
synced 2026-08-24 10:14:36 -05:00
Add normalized PumpMetadata model + BFF adapter
Introduce a typed PumpMetadata TypedDict and pump_metadata()/ _bff_pump_to_metadata() that adapt get_pumper().pumps[] into the stable shape the sync code needs. Maps the new BFF fields to normalized names: assignmentId -> deviceId (UUID), maxDateOfEvents -> maxDateWithEvents, availableDataRange.start -> minDateWithEvents, settings.details -> settings. Verified against the captured account response (7 pumps). Additive only; consumers are migrated off pump_event_metadata() in a follow-up commit.
This commit is contained in:
@@ -147,6 +147,27 @@ class BffPumper(TypedDict, total=False):
|
||||
pumps: List[BffPump]
|
||||
|
||||
|
||||
class PumpMetadata(TypedDict, total=False):
|
||||
"""Normalized per-pump metadata the sync code consumes, adapted from a
|
||||
BffPump (see TandemSourceApi.pump_metadata()). This is the stable
|
||||
replacement for the old reportsfacade PumpEventMetadata shape.
|
||||
|
||||
deviceId is the UUID assignmentId used as the pump-logs path segment (it
|
||||
replaces the old numeric tconnectDeviceId). date fields are ISO-8601
|
||||
strings or None; settings is the pump settings blob (BffPump.settings
|
||||
.details) or None for a pump that has never uploaded.
|
||||
"""
|
||||
deviceId: str
|
||||
serialNumber: str
|
||||
modelNumber: str
|
||||
modelName: str
|
||||
softwareVersion: str
|
||||
algorithm: str
|
||||
maxDateWithEvents: Optional[str]
|
||||
minDateWithEvents: Optional[str]
|
||||
settings: Optional[dict]
|
||||
|
||||
|
||||
class TandemSourceApi:
|
||||
# Common URLs that are shared between regions
|
||||
LOGIN_PAGE_URL = 'https://sso.tandemdiabetes.com/'
|
||||
@@ -568,6 +589,30 @@ class TandemSourceApi:
|
||||
pump settings blob."""
|
||||
return self.get('api/reports/bff/pumper/%s' % (self.pumperId), {})
|
||||
|
||||
@staticmethod
|
||||
def _bff_pump_to_metadata(pump: BffPump) -> PumpMetadata:
|
||||
"""Adapt one BffPump into the normalized PumpMetadata shape."""
|
||||
settings = pump.get('settings')
|
||||
data_range = pump.get('availableDataRange') or {}
|
||||
meta: PumpMetadata = {
|
||||
'deviceId': pump['assignmentId'],
|
||||
'serialNumber': pump['serialNumber'],
|
||||
'modelNumber': pump['modelNumber'],
|
||||
'modelName': pump['modelName'],
|
||||
'softwareVersion': pump['softwareVersion'],
|
||||
'algorithm': pump['algorithm'],
|
||||
'maxDateWithEvents': pump.get('maxDateOfEvents'),
|
||||
'minDateWithEvents': data_range.get('start'),
|
||||
'settings': settings['details'] if settings else None,
|
||||
}
|
||||
return meta
|
||||
|
||||
def pump_metadata(self) -> List[PumpMetadata]:
|
||||
"""Normalized device list adapted from get_pumper(). This is the
|
||||
BFF-backed replacement for pump_event_metadata()."""
|
||||
pumper = self.get_pumper()
|
||||
return [self._bff_pump_to_metadata(p) for p in pumper.get('pumps', [])]
|
||||
|
||||
# Matches the Tandem Source web app's getLogIDList() (55 IDs) as observed in
|
||||
# the live GET api/reports/bff/pump-logs request. Includes FSL3 ids 477/480/486.
|
||||
DEFAULT_EVENT_IDS: List[int] = [229,5,28,4,26,99,279,3,16,59,21,55,20,280,64,65,66,61,33,371,171,369,460,172,370,461,372,480,399,256,213,406,477,394,212,404,214,405,486,447,313,60,14,6,90,230,140,12,11,53,13,63,203,307,191]
|
||||
|
||||
Reference in New Issue
Block a user