Skip to content

Commit ff91fb6

Browse files
authored
Merge pull request #296 from federicopellegatta/feat/workout-schedule
Add workout schedule API support
2 parents 32d0ed5 + a96ea94 commit ff91fb6

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Make your selection:
3939
- **Daily Health & Activity**: 8 methods (today's health data)
4040
- **Advanced Health Metrics**: 10 methods (fitness metrics, HRV, VO2)
4141
- **Historical Data & Trends**: 6 methods (date range queries)
42-
- **Activities & Workouts**: 20 methods (comprehensive activity management)
42+
- **Activities & Workouts**: 21 methods (comprehensive activity management)
4343
- **Body Composition & Weight**: 8 methods (weight tracking, body composition)
4444
- **Goals & Achievements**: 15 methods (challenges, badges, goals)
4545
- **Device & Technical**: 7 methods (device info, settings)
@@ -66,7 +66,7 @@ A comprehensive Python3 API wrapper for Garmin Connect, providing access to heal
6666
This library enables developers to programmatically access Garmin Connect data including:
6767

6868
- **Health Metrics**: Heart rate, sleep, stress, body composition, SpO2, HRV
69-
- **Activity Data**: Workouts, exercises, training status, performance metrics
69+
- **Activity Data**: Workouts, scheduled workouts, exercises, training status, performance metrics
7070
- **Device Information**: Connected devices, settings, alarms, solar data
7171
- **Goals & Achievements**: Personal records, badges, challenges, race predictions
7272
- **Historical Data**: Trends, progress tracking, date range queries

demo.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def __init__(self):
266266
"l": {"desc": "Set activity type", "key": "set_activity_type"},
267267
"m": {"desc": "Create manual activity", "key": "create_manual_activity"},
268268
"n": {"desc": "Delete activity", "key": "delete_activity"},
269+
"o": {
270+
"desc": "Get scheduled workout by ID",
271+
"key": "get_scheduled_workout_by_id",
272+
},
269273
},
270274
},
271275
"6": {
@@ -1976,6 +1980,25 @@ def clean_step_ids(workout_segments):
19761980
print("💡 Workout data validation failed")
19771981

19781982

1983+
def get_scheduled_workout_by_id_data(api: Garmin) -> None:
1984+
"""Get scheduled workout by ID."""
1985+
try:
1986+
scheduled_workout_id = input("Enter scheduled workout ID: ").strip()
1987+
1988+
if not scheduled_workout_id:
1989+
print("❌ Scheduled workout ID is required")
1990+
return
1991+
1992+
call_and_display(
1993+
api.get_scheduled_workout_by_id,
1994+
scheduled_workout_id,
1995+
method_name="get_scheduled_workout_by_id",
1996+
api_call_desc=f"api.get_scheduled_workout_by_id({scheduled_workout_id})",
1997+
)
1998+
except Exception as e:
1999+
print(f"❌ Error getting scheduled workout by ID: {e}")
2000+
2001+
19792002
def set_body_composition_data(api: Garmin) -> None:
19802003
"""Set body composition data."""
19812004
try:
@@ -3272,6 +3295,9 @@ def execute_api_call(api: Garmin, key: str) -> None:
32723295
"get_workout_by_id": lambda: get_workout_by_id_data(api),
32733296
"download_workout": lambda: download_workout_data(api),
32743297
"upload_workout": lambda: upload_workout_data(api),
3298+
"get_scheduled_workout_by_id": lambda: get_scheduled_workout_by_id_data(
3299+
api
3300+
),
32753301
# Body Composition & Weight
32763302
"get_body_composition": lambda: call_and_display(
32773303
api.get_body_composition,

garminconnect/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ def __init__(
267267

268268
self.garmin_workouts = "/workout-service"
269269

270+
self.garmin_workouts_schedule_url = f"{self.garmin_workouts}/schedule"
271+
270272
self.garmin_connect_delete_activity_url = "/activity-service/activity"
271273

272274
self.garmin_graphql_endpoint = "graphql-gateway/graphql"
@@ -2146,6 +2148,18 @@ def upload_workout(
21462148
raise ValueError("workout_json must be a JSON object or array")
21472149
return self.garth.post("connectapi", url, json=payload, api=True).json()
21482150

2151+
def get_scheduled_workout_by_id(
2152+
self, scheduled_workout_id: int | str
2153+
) -> dict[str, Any]:
2154+
"""Return scheduled workout by ID"""
2155+
2156+
scheduled_workout_id = _validate_positive_integer(
2157+
int(scheduled_workout_id), "scheduled_workout_id"
2158+
)
2159+
url = f"{self.garmin_workouts_schedule_url}/{scheduled_workout_id}"
2160+
logger.debug("Requesting scheduled workout by id %d", scheduled_workout_id)
2161+
return self.connectapi(url)
2162+
21492163
def get_menstrual_data_for_date(self, fordate: str) -> dict[str, Any]:
21502164
"""Return menstrual data for date."""
21512165

0 commit comments

Comments
 (0)