Repository navigation
feat: add set_primary_activity_tracker() to choose the primary wearable - #483
christianhaberl wants to merge 2 commits into
Conversation
The web app's Device Priority page sends this request when the settings are
saved: a PUT to
device-service/deviceservice/device-info/{id}/primary-activity-tracker.
The device ID is in the URL; the request works without a body and Garmin
answers 204. get_primary_training_device() then shows the device with
primaryWearableDevice: true. The primary wearable and the primary training
device are independent settings, so set_primary_training_device() alone
does not move steps, stress and sleep to the other device.
Tested live on a real account with two devices. Sending this request
directly through client.put: Garmin answered 204 and the primary wearable
moved to the other device and back, while the training device stayed
unchanged; calling set_primary_training_device() alone left the primary
wearable unchanged. Then with this method: switched the primary wearable from
one device to another and back, reading back with
get_primary_training_device() after each step; it returned None each time
and the training device stayed unchanged.
Added next to set_primary_training_device(), with a unit test, a demo.py
entry, the endpoint table and a changelog line.
|
No actionable comments were generated in the recent review. WalkthroughAdds ChangesPrimary Activity Tracker Selection
Estimated code review effort: 2 (Simple) | ~12 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
actor User
participant Demo as demo.py
participant API as GarminBase
participant Endpoint as Garmin device endpoint
User->>Demo: Choose Set primary wearable
Demo->>API: get_devices()
API-->>Demo: Return device list
Demo->>User: Present device choices
User->>Demo: Select a device
Demo->>API: set_primary_activity_tracker(device_id)
API->>Endpoint: Send bodyless PUT
Endpoint-->>API: Return response
Suggested reviewers: Merge Risk:
|
What
Adds
Garmin.set_primary_activity_tracker(device_id), which sets the device Garmin Connect calls the "Primary Wearable" on its Device Priority page. That device is the source of daily health metrics such as steps, stress and sleep. The library could already set the primary training device (set_primary_training_device()), but not the primary wearable.Why
The two roles are separate settings in Garmin Connect. With two devices (in my case a watch and a band), calling
set_primary_training_device()alone moves only the training role; the primary wearable, which Garmin uses for steps, stress and sleep, stays on the previous device. Switching both needs this second request.Request
Taken from the Garmin Connect web app (Settings → Device Priority → Save), recorded in the browser:
(
/gc-apiis the web app's prefix; throughconnectapithe path starts at/device-service.)The method sends this request through
client.put("connectapi", …)with the existinggarmin_connect_device_urlprefix. The device ID is part of the URL and goes through_coerce_positive_id; no body is sent, and Garmin accepts the request without one.How I tested it
get_primary_training_device()after each step:client.put("connectapi", …): primary wearable A → B → A, Garmin answered 204 each time,primaryWearableDevice: truemoved with it and the primary training device stayed A; for comparison,set_primary_training_device(B)alone moved only the training device, the primary wearable stayed A;Noneeach time, the read-back showed the new primary wearable and the training device stayed A.tests/test_web_endpoints.py: URL, method, no body of any kind, and rejected IDs (0,-1,"abc",1.9,None).demo.pyentry next to "Set primary training device", endpoint table indocs/API_ENDPOINTS.md, method reference regenerated withscripts/gen_method_reference.py, counts inREADME.mdupdated, changelog line under Unreleased.ruff check,ruff format --check,mypy garminconnect --ignore-missing-importsandpytest tests/ --vcr-record=nonepass locally.Note for merging: this PR and #484 (
set_sleep_window()) are independent but both touch the README counts, the[Unreleased]changelog block and the end of the device/sleep tests. Whichever is merged second needs a rebase; I'll rebase it and regenerate the counts (scripts/gen_method_reference.py, 272 methods in demo.py, 350 in the method reference) as soon as the first one is in.Note: the web page sends both requests (training device and primary wearable) when you save, so the two roles look coupled there; through the API they are independent.
Summary by CodeRabbit