Conversation
WalkthroughAdds a new scheduling feature: a Garmin.schedule_workout(workout_id, date_str) method that posts a date payload to the Garmin schedule endpoint, and an interactive demo flow schedule_workout_data(...) that lists workouts, prompts for selection and date, and calls the API. Changes
Sequence DiagramsequenceDiagram
actor User
participant Demo as Demo UI
participant Garmin as Garmin Client
participant Server as Garmin Connect Server
User->>Demo: Choose "s" (schedule workout)
Demo->>Garmin: get_workouts()
Garmin->>Server: GET /workouts
Server-->>Garmin: 200 OK + workout list
Garmin-->>Demo: workout list
Demo->>User: Show workouts
User->>Demo: Select index & enter date (YYYY-MM-DD)
Demo->>Garmin: schedule_workout(workout_id, date_str)
Note over Garmin: validate workout_id and date_str
Garmin->>Server: POST /workouts/{id}/schedule { "date": date_str }
Server-->>Garmin: 200/201 confirmation
Garmin-->>Demo: scheduled response
Demo->>User: Display result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@demo.py`:
- Around line 2314-2322: The code is calling a non-existent method
api.scheduled_workout and unconditionally printing success; change the call to
the correct method api.schedule_workout (matching Garmin.schedule_workout) and
capture its return value from call_and_display (e.g., result =
call_and_display(..., method_name="schedule_workout", api_call_desc=...)); only
print "✅ Workout scheduled successfully!" if the captured result indicates
success (truthy/expected success structure) to prevent false-positive messages.
- Around line 2280-2287: get_workouts() is annotated as returning a dict but
callers (variables named workouts used with enumerate, slicing, or indexing)
expect a list; normalize the response immediately after calling
api.get_workouts() by checking its type and converting to a list: if workouts is
a dict, extract the actual list payload (e.g., workouts =
workouts.get("workouts") or workouts.get("items") if present) and if no list key
exists wrap the dict in [workouts]; otherwise ensure workouts is a list (e.g.,
if not isinstance(workouts, list): workouts = list(workouts)). Apply this
normalization at every call site that assigns to workouts (the calls to
api.get_workouts() that subsequently use enumerate, slicing like [:10] or [-1])
so downstream code can safely use list operations.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
demo.py (1)
2314-2323:⚠️ Potential issue | 🟠 MajorOnly show success when scheduling actually succeeds.
Line 2314 ignores the
(success, result)returned bycall_and_display, and Line 2322 always prints success even on API failure. Also, method labels should matchschedule_workoutfor accurate diagnostics.🐛 Proposed fix
- call_and_display( + success, _ = call_and_display( api.schedule_workout, workout_id, schedule_date, - method_name="scheduled_workout", - api_call_desc=f"api.scheduled_workout({workout_id}, '{schedule_date}') - {workout_name}", + method_name="schedule_workout", + api_call_desc=f"api.schedule_workout({workout_id}, '{schedule_date}') - {workout_name}", ) - - print("✅ Workout scheduled successfully!") + if success: + print("✅ Workout scheduled successfully!")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@demo.py` around lines 2314 - 2323, call_and_display currently returns (success, result) but the code ignores it and always prints success; change the call to capture the result from call_and_display (e.g., success, result = call_and_display(...)) and only print "✅ Workout scheduled successfully!" when success is truthy; also update the method_name and api_call_desc to use the actual method name "schedule_workout" and a matching api_call_desc (e.g., f"api.schedule_workout({workout_id}, '{schedule_date}') - {workout_name}") so diagnostics reflect the real API call; keep the call target api.schedule_workout and variables workout_id, schedule_date, workout_name unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@demo.py`:
- Around line 2314-2323: call_and_display currently returns (success, result)
but the code ignores it and always prints success; change the call to capture
the result from call_and_display (e.g., success, result = call_and_display(...))
and only print "✅ Workout scheduled successfully!" when success is truthy; also
update the method_name and api_call_desc to use the actual method name
"schedule_workout" and a matching api_call_desc (e.g.,
f"api.schedule_workout({workout_id}, '{schedule_date}') - {workout_name}") so
diagnostics reflect the real API call; keep the call target api.schedule_workout
and variables workout_id, schedule_date, workout_name unchanged.
Added endpoint for scheduling workouts. Happy to help!
Summary by CodeRabbit
New Features
Bug Fixes