Skip to content

feat: add set_primary_activity_tracker() to choose the primary wearable - #483

Open
christianhaberl wants to merge 2 commits into
cyberjunky:masterfrom
christianhaberl:primary-activity-tracker
Open

christianhaberl wants to merge 2 commits into
cyberjunky:masterfrom
christianhaberl:primary-activity-tracker

Conversation

@christianhaberl

@christianhaberl christianhaberl commented Nov 18, 2026 •

Copy link
Copy Markdown

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:

PUT /gc-api/device-service/deviceservice/device-info/{deviceId}/primary-activity-tracker → 204

(/gc-api is the web app's prefix; through connectapi the path starts at /device-service.)

The method sends this request through client.put("connectapi", …) with the existing garmin_connect_device_url prefix. 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

  • Live against my account with two devices, in two runs, reading back with get_primary_training_device() after each step:
    • first the bare request through client.put("connectapi", …): primary wearable A → B → A, Garmin answered 204 each time, primaryWearableDevice: true moved 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;
    • then the new method: primary wearable A → B → A, it returned None each time, the read-back showed the new primary wearable and the training device stayed A.
  • Unit test in tests/test_web_endpoints.py: URL, method, no body of any kind, and rejected IDs (0, -1, "abc", 1.9, None).
  • demo.py entry next to "Set primary training device", endpoint table in docs/API_ENDPOINTS.md, method reference regenerated with scripts/gen_method_reference.py, counts in README.md updated, changelog line under Unreleased.
  • ruff check, ruff format --check, mypy garminconnect --ignore-missing-imports and pytest tests/ --vcr-record=none pass 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

  • New Features
    • Added the ability to set a primary wearable independently of the primary training device.
    • Added a demo menu option to select a device and set it as the primary wearable.
  • Documentation
    • Updated the API reference and method counts to include the new capability.
    • Clarified how the primary wearable relates to the primary training device.

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.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Adds set_primary_activity_tracker(device_id), which validates the device ID and sends a bodyless PUT. The demo adds a device-selection option for the method. Documentation and tests describe the request and its validation.

Changes

Primary Activity Tracker Selection

Layer / File(s) Summary
Add the API method and document its request
garminconnect/api/base.py, tests/test_web_endpoints.py, docs/API_ENDPOINTS.md, CHANGELOG.md
GarminBase validates the device ID and sends a bodyless PUT. Tests cover the request and invalid IDs. The endpoint documentation and changelog describe the method and its distinction from the primary training device.
Connect device selection to the API
demo.py, README.md
The demo adds a menu option that lists devices and calls the method for the selected device. The README adds the method reference and updates method counts.

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
Loading

Suggested reviewers: cyberjunky

Merge Risk: Minimal · up to 601e3

This adds a validated method for selecting the primary wearable, plus demo and documentation updates. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the new public method set_primary_activity_tracker() and its purpose of choosing the primary wearable. The raw summary and objectives confirm this is the main change: a new method in…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the new public method set_primary_activity_tracker() and its purpose of choosing the primary wearable. The raw summary and objectives confirm this is the main change: a new method in garminconnect/api/base.py, with its endpoint, tests, demo option, docs, and README counts. The title is specific and matches the core change. It uses the conventional "feat:" prefix.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

👋 New to CodeRabbit? Try chatting in this PR!

Ask questions about the changes or discuss a review suggestion by mentioning @coderabbitai in a PR comment or a reply to a CodeRabbit review comment.

Try: @coderabbitai explain the changes in this PR and what I should focus on when reviewing.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 82bc110 and 601e3da.

Files selected for processing: 6

  • CHANGELOG.md
  • README.md
  • demo.py
  • docs/API_ENDPOINTS.md
  • garminconnect/api/base.py
  • tests/test_web_endpoints.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant