Skip to content

Commit aaf687f

Browse files
authored
Merge pull request #358 from andrebbruno/fix/swimming-workout-sporttype-id
fix(workout): correct SwimmingWorkout sportTypeId to 4
2 parents b1dfb0d + 0c1fa5e commit aaf687f

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

garminconnect/workout.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ class SwimmingWorkout(BaseWorkout):
219219

220220
sportType: dict[str, Any] = Field(
221221
default_factory=lambda: {
222-
"sportTypeId": SportType.SWIMMING,
222+
# Garmin workout-service expects swimming sportTypeId=4.
223+
# Using 3 gets normalized to sportTypeKey="other" on upload.
224+
"sportTypeId": 4,
223225
"sportTypeKey": "swimming",
224226
"displayOrder": 3,
225227
}

tests/test_workout_constants.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
Prevents silent drift of constant values (see issue #333).
44
"""
55

6-
from garminconnect.workout import ConditionType, SportType, StepType, TargetType
6+
from garminconnect.workout import (
7+
ConditionType,
8+
SportType,
9+
StepType,
10+
SwimmingWorkout,
11+
TargetType,
12+
WorkoutSegment,
13+
create_warmup_step,
14+
)
715

816

917
def test_target_type_ids() -> None:
@@ -47,3 +55,21 @@ def test_sport_type_ids() -> None:
4755
assert SportType.FITNESS_EQUIPMENT == 6
4856
assert SportType.HIKING == 7
4957
assert SportType.OTHER == 8
58+
59+
60+
def test_swimming_workout_uses_expected_sport_type_id() -> None:
61+
"""Ensure typed swimming workouts upload as sportTypeKey=swimming."""
62+
workout = SwimmingWorkout(
63+
workoutName="Regression Swim",
64+
estimatedDurationInSecs=300,
65+
workoutSegments=[
66+
WorkoutSegment(
67+
segmentOrder=1,
68+
sportType={"sportTypeId": 4, "sportTypeKey": "swimming"},
69+
workoutSteps=[create_warmup_step(300.0)],
70+
)
71+
],
72+
)
73+
payload = workout.to_dict()
74+
assert payload["sportType"]["sportTypeId"] == 4
75+
assert payload["sportType"]["sportTypeKey"] == "swimming"

0 commit comments

Comments
 (0)