Skip to content

Commit 7748f64

Browse files
committed
Recorded new VCR cassettes, some need fixing
1 parent e65db36 commit 7748f64

19 files changed

+1550
-16397
lines changed

garminconnect/__init__.py

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -304,36 +304,14 @@ def login(self, /, tokenstore: str | None = None) -> tuple[str | None, str | Non
304304
tokenstore = tokenstore or os.getenv("GARMINTOKENS")
305305

306306
try:
307+
token1 = None
308+
token2 = None
309+
307310
if tokenstore:
308311
if len(tokenstore) > 512:
309312
self.garth.loads(tokenstore)
310313
else:
311314
self.garth.load(tokenstore)
312-
313-
# Validate profile data exists
314-
if not hasattr(self.garth, "profile") or not self.garth.profile:
315-
raise GarminConnectAuthenticationError(
316-
"Failed to login to get user profile"
317-
)
318-
319-
self.display_name = self.garth.profile.get("displayName")
320-
self.full_name = self.garth.profile.get("fullName")
321-
322-
if not self.display_name:
323-
raise GarminConnectAuthenticationError(
324-
"Invalid profile data"
325-
)
326-
327-
settings = self.garth.connectapi(self.garmin_connect_user_settings_url)
328-
329-
if not settings or "userData" not in settings:
330-
raise GarminConnectAuthenticationError(
331-
"Failed to retrieve user settings"
332-
)
333-
334-
self.unit_system = settings["userData"].get("measurementSystem")
335-
336-
return None, None
337315
else:
338316
# Validate credentials before attempting login
339317
if not self.username or not self.password:
@@ -342,7 +320,7 @@ def login(self, /, tokenstore: str | None = None) -> tuple[str | None, str | Non
342320
)
343321

344322
# Validate email format when actually used for login
345-
if (not self.is_cn) and self.username and "@" not in self.username:
323+
if self.username and "@" not in self.username:
346324
raise GarminConnectAuthenticationError(
347325
"Email must contain '@' symbol"
348326
)
@@ -360,30 +338,33 @@ def login(self, /, tokenstore: str | None = None) -> tuple[str | None, str | Non
360338
prompt_mfa=self.prompt_mfa,
361339
)
362340

363-
# Validate profile data after login
364-
if not hasattr(self.garth, "profile") or not self.garth.profile:
365-
raise GarminConnectAuthenticationError(
366-
"Login succeeded but no profile data received"
367-
)
341+
# Validate profile data exists
342+
if not hasattr(self.garth, "profile") or not self.garth.profile:
343+
raise GarminConnectAuthenticationError(
344+
"Failed to retrieve profile"
345+
)
346+
347+
self.display_name = self.garth.profile.get("displayName")
348+
self.full_name = self.garth.profile.get("fullName")
368349

369-
self.display_name = self.garth.profile.get("displayName")
370-
self.full_name = self.garth.profile.get("fullName")
350+
if not self.display_name:
351+
raise GarminConnectAuthenticationError(
352+
"Invalid profile data found"
353+
)
371354

372-
if not self.display_name:
373-
raise GarminConnectAuthenticationError(
374-
"Invalid profile data: missing displayName"
375-
)
355+
settings = self.garth.connectapi(self.garmin_connect_user_settings_url)
376356

377-
settings = self.garth.connectapi(
378-
self.garmin_connect_user_settings_url
379-
)
357+
if not settings:
358+
raise GarminConnectAuthenticationError(
359+
"Failed to retrieve user settings"
360+
)
380361

381-
if not settings or "userData" not in settings:
382-
raise GarminConnectAuthenticationError(
383-
"Failed to retrieve user settings"
384-
)
362+
if "userData" not in settings:
363+
raise GarminConnectAuthenticationError(
364+
"Invalid user settings found"
365+
)
385366

386-
self.unit_system = settings["userData"].get("measurementSystem")
367+
self.unit_system = settings["userData"].get("measurementSystem")
387368

388369
return token1, token2
389370

tests/cassettes/test_all_day_stress.yaml

Lines changed: 56 additions & 434 deletions
Large diffs are not rendered by default.

tests/cassettes/test_body_battery.yaml

Lines changed: 60 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,70 +10,76 @@ interactions:
1010
- Bearer SANITIZED
1111
Connection:
1212
- keep-alive
13+
Cookie:
14+
- _cfuvid=SANITIZED
1315
User-Agent:
14-
- Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15
15-
(KHTML, like Gecko) Mobile/15E148
16+
- GCM-iOS-5.7.2.1
1617
method: GET
1718
uri: https://connectapi.garmin.com/userprofile-service/userprofile/user-settings
1819
response:
1920
body:
20-
string: '{"id": 2591602, "userData": {"gender": "MALE", "weight": 79800.0, "height":
21-
182.0, "timeFormat": "time_twenty_four_hr", "birthDate": "1984-10-17", "measurementSystem":
22-
"metric", "activityLevel": null, "handedness": "RIGHT", "powerFormat": {"formatId":
23-
30, "formatKey": "watt", "minFraction": 0, "maxFraction": 0, "groupingUsed":
24-
true, "displayFormat": null}, "heartRateFormat": {"formatId": 21, "formatKey":
25-
"bpm", "minFraction": 0, "maxFraction": 0, "groupingUsed": false, "displayFormat":
26-
null}, "firstDayOfWeek": {"dayId": 2, "dayName": "sunday", "sortOrder": 2,
27-
"isPossibleFirstDay": true}, "vo2MaxRunning": 46.0, "vo2MaxCycling": null,
28-
"lactateThresholdSpeed": 0.34722125000000004, "lactateThresholdHeartRate":
29-
null, "diveNumber": null, "intensityMinutesCalcMethod": "AUTO", "moderateIntensityMinutesHrZone":
21+
string: '{"id": 82413233, "userData": {"gender": "MALE", "weight": 85100.0,
22+
"height": 184.0, "timeFormat": "time_twenty_four_hr", "birthDate": "1966-09-15",
23+
"measurementSystem": "metric", "activityLevel": 4, "handedness": "RIGHT",
24+
"powerFormat": {"formatId": 30, "formatKey": "watt", "minFraction": 0, "maxFraction":
25+
0, "groupingUsed": true, "displayFormat": null}, "heartRateFormat": {"formatId":
26+
21, "formatKey": "bpm", "minFraction": 0, "maxFraction": 0, "groupingUsed":
27+
false, "displayFormat": null}, "firstDayOfWeek": {"dayId": 3, "dayName": "monday",
28+
"sortOrder": 3, "isPossibleFirstDay": true}, "vo2MaxRunning": 39.0, "vo2MaxCycling":
29+
null, "lactateThresholdSpeed": null, "lactateThresholdHeartRate": null, "diveNumber":
30+
null, "intensityMinutesCalcMethod": "AUTO", "moderateIntensityMinutesHrZone":
3031
3, "vigorousIntensityMinutesHrZone": 4, "hydrationMeasurementUnit": "milliliter",
3132
"hydrationContainers": [], "hydrationAutoGoalEnabled": true, "firstbeatMaxStressScore":
3233
null, "firstbeatCyclingLtTimestamp": null, "firstbeatRunningLtTimestamp":
33-
1044719868, "thresholdHeartRateAutoDetected": true, "ftpAutoDetected": null,
34-
"trainingStatusPausedDate": null, "weatherLocation": {"useFixedLocation":
35-
false, "latitude": null, "longitude": null, "locationName": null, "isoCountryCode":
36-
null, "postalCode": null}, "golfDistanceUnit": "statute_us", "golfElevationUnit":
37-
null, "golfSpeedUnit": null, "externalBottomTime": null}, "userSleep": {"sleepTime":
38-
80400, "defaultSleepTime": false, "wakeTime": 24000, "defaultWakeTime": false},
39-
"connectDate": null, "sourceType": null}'
34+
null, "thresholdHeartRateAutoDetected": null, "ftpAutoDetected": null, "trainingStatusPausedDate":
35+
null, "weatherLocation": {"useFixedLocation": null, "latitude": null, "longitude":
36+
null, "locationName": null, "isoCountryCode": null, "postalCode": null}, "golfDistanceUnit":
37+
null, "golfElevationUnit": null, "golfSpeedUnit": null, "externalBottomTime":
38+
null, "availableTrainingDays": ["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY",
39+
"FRIDAY", "SATURDAY", "SUNDAY"], "preferredLongTrainingDays": ["SATURDAY",
40+
"SUNDAY"], "virtualCaddieDataSource": null, "numberDivesAutomatically": null},
41+
"userSleep": {"sleepTime": 81000, "defaultSleepTime": false, "wakeTime": 23400,
42+
"defaultWakeTime": false}, "connectDate": null, "sourceType": null, "userSleepWindows":
43+
[{"sleepWindowFrequency": "SUNDAY", "startSleepTimeSecondsFromMidnight": 81000,
44+
"endSleepTimeSecondsFromMidnight": 23400}, {"sleepWindowFrequency": "MONDAY",
45+
"startSleepTimeSecondsFromMidnight": 81000, "endSleepTimeSecondsFromMidnight":
46+
23400}, {"sleepWindowFrequency": "TUESDAY", "startSleepTimeSecondsFromMidnight":
47+
81000, "endSleepTimeSecondsFromMidnight": 23400}, {"sleepWindowFrequency":
48+
"WEDNESDAY", "startSleepTimeSecondsFromMidnight": 81000, "endSleepTimeSecondsFromMidnight":
49+
23400}, {"sleepWindowFrequency": "THURSDAY", "startSleepTimeSecondsFromMidnight":
50+
81000, "endSleepTimeSecondsFromMidnight": 23400}, {"sleepWindowFrequency":
51+
"FRIDAY", "startSleepTimeSecondsFromMidnight": 81000, "endSleepTimeSecondsFromMidnight":
52+
23400}, {"sleepWindowFrequency": "SATURDAY", "startSleepTimeSecondsFromMidnight":
53+
81000, "endSleepTimeSecondsFromMidnight": 23400}, {"sleepWindowFrequency":
54+
"DAILY", "startSleepTimeSecondsFromMidnight": 81000, "endSleepTimeSecondsFromMidnight":
55+
23400}]}'
4056
headers:
41-
CF-Cache-Status:
42-
- DYNAMIC
4357
CF-RAY:
44-
- 7f8a7b014d17b6e2-QRO
58+
- 9782f239b8bdb674-AMS
59+
Cache-Control:
60+
- no-cache, no-store, private
4561
Connection:
4662
- keep-alive
63+
Content-Encoding:
64+
- gzip
4765
Content-Type:
4866
- application/json;charset=UTF-8
4967
Date:
50-
- Fri, 18 Aug 2023 13:25:02 GMT
68+
- Mon, 01 Sep 2025 07:10:09 GMT
5169
NEL:
5270
- '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
5371
Report-To:
54-
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=5fw6qcq0NdNdbleOS%2BWsMpFjTu6%2BU2E7IbbvmX8RF38%2Fitx8T5Eai8xRMWKiC%2F728gP0zlJeNtiIprepe9WLjNWkKmBb4g%2F2KiF7%2FRzTL3epslvndR22jovxvhF7Y5HZXsL%2Fzw4pRA%3D%3D"}],"group":"cf-nel","max_age":604800}'
72+
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=G%2BWUPiZNbMV8FL%2FYCukfvpmxJceQBc3RdOn2ytHnbNRUHcMqKJEZ2tySWXP0FcerZCZ%2F5V6pDsC9l71xqELJvkR0zbPggrd6j0PSXcAwphoxlrJq5CdpC4ozDbs6nv3Alk4J9kKqwK6CJ2YCtPQ5cLenoA%3D%3D"}],"group":"cf-nel","max_age":604800}'
5573
Server:
5674
- cloudflare
5775
Transfer-Encoding:
5876
- chunked
5977
alt-svc:
6078
- h3=":443"; ma=86400
61-
cache-control:
62-
- no-cache, no-store, private
79+
cf-cache-status:
80+
- DYNAMIC
6381
pragma:
6482
- no-cache
65-
set-cookie:
66-
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
67-
Secure
68-
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
69-
Secure
70-
- SameSite=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
71-
Secure
72-
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
73-
Secure
74-
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
75-
Secure
76-
- _cfuvid=SANITIZED; path=SANITIZED; domain=SANITIZED; HttpOnly; Secure; SameSite=SANITIZED
7783
status:
7884
code: 200
7985
message: OK
@@ -89,57 +95,47 @@ interactions:
8995
Connection:
9096
- keep-alive
9197
Cookie:
92-
- _cfuvid=SANITIZED; ADRUM_BT1=SANITIZED; ADRUM_BTa=SANITIZED; SameSite=SANITIZED
98+
- _cfuvid=SANITIZED
9399
User-Agent:
94-
- Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15
95-
(KHTML, like Gecko) Mobile/15E148
100+
- GCM-iOS-5.7.2.1
96101
method: GET
97102
uri: https://connectapi.garmin.com/wellness-service/wellness/bodyBattery/reports/daily?startDate=2023-07-01&endDate=2023-07-01
98103
response:
99104
body:
100-
string: '[{"date": "2023-07-01", "charged": 43, "drained": 43, "startTimestampGMT":
101-
"2023-07-01T06:00:00.0", "endTimestampGMT": "2023-07-02T06:00:00.0", "startTimestampLocal":
105+
string: '[{"date": "2023-07-01", "charged": 23, "drained": 23, "startTimestampGMT":
106+
"2023-06-30T22:00:00.0", "endTimestampGMT": "2023-07-01T22:00:00.0", "startTimestampLocal":
102107
"2023-07-01T00:00:00.0", "endTimestampLocal": "2023-07-02T00:00:00.0", "bodyBatteryValuesArray":
103-
[[1688191200000, 5], [1688214060000, 48], [1688220000000, 41], [1688248260000,
104-
23], [1688248800000, 23], [1688269140000, 5]], "bodyBatteryValueDescriptorDTOList":
108+
[[1688169600001, null], [1688169600002, null], [1688169600003, null], [1688169600004,
109+
null], [1688169600005, null], [1688169600006, null]], "bodyBatteryValueDescriptorDTOList":
105110
[{"bodyBatteryValueDescriptorIndex": 0, "bodyBatteryValueDescriptorKey": "timestamp"},
106111
{"bodyBatteryValueDescriptorIndex": 1, "bodyBatteryValueDescriptorKey": "bodyBatteryLevel"}]}]'
107112
headers:
108-
CF-Cache-Status:
109-
- DYNAMIC
110113
CF-RAY:
111-
- 7f8a7b0288481549-QRO
114+
- 9782f23b4f8e0e3c-AMS
115+
Cache-Control:
116+
- no-cache, no-store, private
112117
Connection:
113118
- keep-alive
119+
Content-Encoding:
120+
- gzip
114121
Content-Type:
115-
- application/json;charset=UTF-8
122+
- application/json
116123
Date:
117-
- Fri, 18 Aug 2023 13:25:02 GMT
124+
- Mon, 01 Sep 2025 07:10:09 GMT
118125
NEL:
119126
- '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
120127
Report-To:
121-
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=vuNozV%2Btdqrb2pnWC8vZa8XsRe8ATc8162AEj6jyD7wtVGJRTuI3LHxioV%2BMV%2FGZ%2BwoicMvVtiKVYZl2xLmGkhhuglHn0eUgQ7TtGcBIOHDPqxdHxwMC%2BbkPjL6ZgxgExIOyFPSPqQ%3D%3D"}],"group":"cf-nel","max_age":604800}'
128+
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=87s74swcBrQP9pFo7I1R7Z1pwGZX50neeDStpT%2Bbk86yO7bWz97uzjfeZOdtFzlZXdc%2BlQj%2FGlivvF9TX6kcVWZptQQbbs7ADAFfz63kUfjdr3phj%2BXOwT3VLn5oTQw4CjH0ZAjt3Q94fbtjQoTg5ZOHsg%3D%3D"}],"group":"cf-nel","max_age":604800}'
122129
Server:
123130
- cloudflare
124131
Transfer-Encoding:
125132
- chunked
126133
alt-svc:
127134
- h3=":443"; ma=86400
128-
cache-control:
129-
- no-cache, no-store, private
135+
cf-cache-status:
136+
- DYNAMIC
130137
pragma:
131138
- no-cache
132-
set-cookie:
133-
- ADRUM_BT1=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
134-
Secure
135-
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
136-
Secure
137-
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
138-
Secure
139-
- ADRUM_BTa=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
140-
Secure
141-
- SameSite=SANITIZED; Max-Age=SANITIZED; Expires=SANITIZED; Path=SANITIZED;
142-
Secure
143139
status:
144140
code: 200
145141
message: OK

0 commit comments

Comments
 (0)