Skip to content

Commit eab98de

Browse files
cyberjunkyclaude
andcommitted
feat(demo): add Activity Editing menu for set_activity_description / exercise_sets
Adds a new "✏️ Activity Editing" category (d) covering the two recently merged methods: - set_activity_description (PR #367) - set_activity_exercise_sets (PR #368) The Activities category was full (all 36 single-key slots used), so these write-operations get their own category. The exercise-sets demo does a safe round-trip (re-submits current sets unchanged) with confirmation, since the endpoint has replace-all semantics. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6dfc315 commit eab98de

1 file changed

Lines changed: 98 additions & 0 deletions

File tree

demo.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,19 @@ def __init__(self):
562562
},
563563
},
564564
},
565+
"d": {
566+
"name": "✏️ Activity Editing",
567+
"options": {
568+
"1": {
569+
"desc": "Set activity description (latest activity)",
570+
"key": "set_activity_description",
571+
},
572+
"2": {
573+
"desc": "Set activity exercise sets (strength activity)",
574+
"key": "set_activity_exercise_sets",
575+
},
576+
},
577+
},
565578
}
566579

567580
current_category = None
@@ -3291,6 +3304,89 @@ def set_activity_type_data(api: Garmin) -> None:
32913304
print(f"❌ Error setting activity type: {e}")
32923305

32933306

3307+
def set_activity_description_data(api: Garmin) -> None:
3308+
"""Set the description of the most recent activity."""
3309+
try:
3310+
activities = api.get_activities(0, 1)
3311+
if not activities:
3312+
print("❌ No activities found")
3313+
return
3314+
3315+
activity = activities[0]
3316+
activity_id = activity["activityId"]
3317+
current = activity.get("description") or "(none)"
3318+
print(f"Activity: {activity.get('activityName')} (id {activity_id})")
3319+
print(f"Current description: {current}")
3320+
3321+
new_desc = input("Enter new description (or 'q' to cancel): ").strip()
3322+
if new_desc.lower() == "q":
3323+
print("❌ Cancelled")
3324+
return
3325+
3326+
call_and_display(
3327+
api.set_activity_description,
3328+
activity_id,
3329+
new_desc,
3330+
method_name="set_activity_description",
3331+
api_call_desc=f"api.set_activity_description({activity_id}, '{new_desc}')",
3332+
)
3333+
print("✅ Activity description updated!")
3334+
except Exception as e:
3335+
print(f"❌ Error setting activity description: {e}")
3336+
3337+
3338+
def set_activity_exercise_sets_data(api: Garmin) -> None:
3339+
"""Replace exercise sets on a strength-training activity.
3340+
3341+
Demonstrates the round-trip: fetch the current sets, then re-submit the
3342+
exact same payload (replace-all semantics). Re-submitting unchanged data
3343+
is a safe no-op that proves the endpoint without altering the activity.
3344+
"""
3345+
try:
3346+
activities = api.get_activities(0, 20)
3347+
strength_activity = None
3348+
for activity in activities:
3349+
type_key = activity.get("activityType", {}).get("typeKey", "")
3350+
if "strength" in type_key.lower() or "training" in type_key.lower():
3351+
strength_activity = activity
3352+
break
3353+
3354+
if not strength_activity:
3355+
print("ℹ️ No strength training activities found")
3356+
return
3357+
3358+
activity_id = strength_activity["activityId"]
3359+
current = api.get_activity_exercise_sets(activity_id)
3360+
sets = current.get("exerciseSets") if isinstance(current, dict) else None
3361+
if not sets:
3362+
print(f"ℹ️ Activity {activity_id} has no exercise sets to replace")
3363+
return
3364+
3365+
print(f"Activity {activity_id} has {len(sets)} exercise set(s).")
3366+
print(
3367+
"⚠️ This REPLACES all exercise sets (replace-all). The demo re-submits "
3368+
"the same payload unchanged, so nothing actually changes."
3369+
)
3370+
confirm = input("Re-submit current sets? (yes/no): ").strip().lower()
3371+
if confirm != "yes":
3372+
print("❌ Cancelled")
3373+
return
3374+
3375+
call_and_display(
3376+
api.set_activity_exercise_sets,
3377+
activity_id,
3378+
{"exerciseSets": sets},
3379+
method_name="set_activity_exercise_sets",
3380+
api_call_desc=(
3381+
f"api.set_activity_exercise_sets({activity_id}, "
3382+
f"{{'exerciseSets': <{len(sets)} sets>}})"
3383+
),
3384+
)
3385+
print("✅ Exercise sets submitted!")
3386+
except Exception as e:
3387+
print(f"❌ Error setting exercise sets: {e}")
3388+
3389+
32943390
def create_manual_activity_data(api: Garmin) -> None:
32953391
"""Create manual activity."""
32963392
try:
@@ -4239,6 +4335,8 @@ def execute_api_call(api: Garmin, key: str) -> None:
42394335
# Activity Management
42404336
"set_activity_name": lambda: set_activity_name_data(api),
42414337
"set_activity_type": lambda: set_activity_type_data(api),
4338+
"set_activity_description": lambda: set_activity_description_data(api),
4339+
"set_activity_exercise_sets": lambda: set_activity_exercise_sets_data(api),
42424340
"create_manual_activity": lambda: create_manual_activity_data(api),
42434341
"delete_activity": lambda: delete_activity_data(api),
42444342
"get_activities_by_date": lambda: call_and_display(

0 commit comments

Comments
 (0)