Skip to content

Conversation

@Tourniercy
Copy link
Contributor

@Tourniercy Tourniercy commented Oct 25, 2025

PR to add a activities count endpoint
So we can have the total activities and use the start and the limit from get_activities endpoint with more knowledge

Summary by CodeRabbit

  • New Features
    • Retrieve your total activity count from Garmin Connect for quick access to activity statistics and summaries.
    • Provides a clear result suitable for dashboards and summary screens, with graceful handling and user-facing error reporting when the service does not return data.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 25, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid enum value. Expected 'chill' | 'assertive', received 'pythonic' at "reviews.profile"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

A new public attribute garmin_connect_activities_count and method count_activities() were added to the Garmin class. The method requests the new endpoint, returns the totalCount from the JSON response, and raises GarminConnectConnectionError if no data is received.

Changes

Cohort / File(s) Summary
New API surface for activities count
garminconnect/__init__.py
Added public attribute garmin_connect_activities_count containing the endpoint URL and new method count_activities() which requests the endpoint, validates response presence, and returns totalCount or raises GarminConnectConnectionError on missing data.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GarminClass as Garmin
    participant API as Garmin API

    Client->>GarminClass: call count_activities()
    GarminClass->>API: HTTP GET garmin_connect_activities_count
    alt API returns JSON with totalCount
        API-->>GarminClass: { totalCount: N, ... }
        GarminClass-->>Client: return N
    else API returns empty/invalid
        API-->>GarminClass: {} / null
        GarminClass-->>Client: raise GarminConnectConnectionError
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify extraction of totalCount and its type/validation
  • Check error raising (GarminConnectConnectionError) path when response missing
  • Confirm the endpoint URL value assigned to garmin_connect_activities_count

Poem

🐰 A curious rabbit counts each run,
Hops to an endpoint in morning sun,
Fetches a number, returns it bright,
If silence comes, it raises a plight,
Hooray — totals found, the tally's done!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Add activities count endpoint and method to retrieve total activities" accurately summarizes the main changes in the changeset. The title clearly identifies both key additions: the new endpoint URL attribute (garmin_connect_activities_count) and the new method (count_activities()). The title is concise, specific, and uses clear language without vague or generic terms. A teammate scanning the repository history would immediately understand that this PR adds functionality to retrieve the total count of activities, which aligns with the stated PR objective of providing the total activities count for better use of pagination parameters.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 749c248 and 08c0a20.

📒 Files selected for processing (1)
  • garminconnect/__init__.py (2 hunks)
🔇 Additional comments (1)
garminconnect/__init__.py (1)

243-243: LGTM! Endpoint URL follows existing conventions.

The new endpoint URL is consistent with other activity-related endpoints and follows the established naming pattern.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
garminconnect/__init__.py (1)

1522-1531: Excellent implementation - past review feedback incorporated.

The defensive check suggested in the previous review has been implemented correctly. The method follows the established patterns in the codebase (similar to get_device_solar_data on Line 1496) and handles error cases appropriately.

Optional type safety enhancement:

While the current implementation is consistent with the rest of the codebase, you could add validation that totalCount is actually an integer and not None to ensure the return type guarantee:

     activities_count = self.connectapi(url)
     if not activities_count or "totalCount" not in activities_count:
         raise GarminConnectConnectionError("No activities count data received")
+    
+    total_count = activities_count["totalCount"]
+    if not isinstance(total_count, int):
+        raise GarminConnectConnectionError(f"Unexpected totalCount type: {type(total_count)}")
+    
-    return activities_count["totalCount"]
+    return total_count

This would protect against unexpected API responses, though it's not done elsewhere in the codebase, so this is purely optional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 08c0a20 and 5c65247.

📒 Files selected for processing (1)
  • garminconnect/__init__.py (2 hunks)
🔇 Additional comments (1)
garminconnect/__init__.py (1)

243-243: LGTM! Endpoint URL follows established patterns.

The new garmin_connect_activities_count endpoint is correctly placed alongside the related activities endpoints and follows the naming conventions used throughout the class.

@cyberjunky
Copy link
Owner

@Tourniercy thank you for this PR!

@cyberjunky cyberjunky merged commit b622c8a into cyberjunky:master Nov 4, 2025
1 check passed
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.

2 participants