Skip to content

TargetType.HEART_RATE constant is incorrect (maps to power zone, not heart rate) #333

@Om3rr

Description

@Om3rr

Bug

The TargetType class in garminconnect/workout.py has an incorrect constant for heart rate:

class TargetType:
    NO_TARGET = 1
    HEART_RATE = 2  # ← this is wrong
    CADENCE = 3
    SPEED = 4
    POWER = 5
    OPEN = 6

Using TargetType.HEART_RATE (value 2) when building a workout step results in Garmin storing the target as power zone (workoutTargetTypeKey: "power.zone"), not heart rate.

Steps to reproduce

from garminconnect.workout import ExecutableStep, TargetType

step = ExecutableStep(
    stepOrder=1,
    stepType={"stepTypeId": 3, "stepTypeKey": "interval", "displayOrder": 3},
    endCondition={"conditionTypeId": 2, "conditionTypeKey": "time", "displayOrder": 2, "displayable": True},
    endConditionValue=300.0,
    targetType={
        "workoutTargetTypeId": TargetType.HEART_RATE,  # value = 2
        "workoutTargetTypeKey": "heart.rate.zone",
        "displayOrder": 2,
    },
    targetValueOne=120,
    targetValueTwo=150,
)

After uploading and fetching back via get_workout_by_id(), Garmin returns:

"targetType": {
  "workoutTargetTypeId": 2,
  "workoutTargetTypeKey": "power.zone"
}

Fix

Garmin's actual target type ID for heart rate zones is 4, not 2. The correct constants should be:

class TargetType:
    NO_TARGET = 1
    POWER = 2        # power.zone
    CADENCE = 3      # cadence
    HEART_RATE = 4   # heart.rate.zone
    SPEED = 5        # speed.zone
    OPEN = 6         # open

Using workoutTargetTypeId: 4 with workoutTargetTypeKey: "heart.rate.zone" produces the correct result verified by fetching the workout back from the API.

Environment

  • garminconnect version: 0.2.40
  • Python: 3.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions