@@ -1771,32 +1771,60 @@ def get_activity_exercise_sets_data(api: Garmin) -> None:
17711771
17721772
17731773def get_training_plan_by_id_data (api : Garmin ) -> None :
1774- """Get training plan by ID. adaptive plans are not supported. use get_adaptive_training_plan_by_id instead"""
1775- try :
1776- training_plans = api .get_training_plans ()["trainingPlanList" ]
1777- if training_plans :
1778- plan_id = training_plans [- 1 ]["trainingPlanId" ]
1779- plan_name = training_plans [- 1 ]["name" ]
1780- plan_category = training_plans [- 1 ]["trainingPlanCategory" ]
1774+ """Get training plan details by ID (routes FBT_ADAPTIVE plans to the adaptive endpoint)."""
1775+ resp = api .get_training_plans () or {}
1776+ training_plans = resp .get ("trainingPlanList" ) or []
1777+ if not training_plans :
1778+ print ("ℹ️ No training plans found" )
1779+ return
17811780
1782- if plan_category == "FBT_ADAPTIVE" :
1783- call_and_display (
1784- api .get_adaptive_training_plan_by_id ,
1785- plan_id ,
1786- method_name = "get_adaptive_training_plan_by_id" ,
1787- api_call_desc = f"api.get_adaptive_training_plan_by_id({ plan_id } ) - { plan_name } " ,
1781+ user_input = input ("Enter training plan ID (press Enter for most recent): " ).strip ()
1782+ selected = None
1783+ if user_input :
1784+ try :
1785+ wanted_id = int (user_input )
1786+ selected = next (
1787+ (
1788+ p
1789+ for p in training_plans
1790+ if int (p .get ("trainingPlanId" , 0 )) == wanted_id
1791+ ),
1792+ None ,
1793+ )
1794+ if not selected :
1795+ print (
1796+ f"ℹ️ Plan ID { wanted_id } not found in your plans; attempting fetch anyway"
17881797 )
1798+ plan_id = wanted_id
1799+ plan_name = f"Plan { wanted_id } "
1800+ plan_category = None
17891801 else :
1790- call_and_display (
1791- api .get_training_plan_by_id ,
1792- plan_id ,
1793- method_name = "get_training_plan_by_id" ,
1794- api_call_desc = f"api.get_training_plan_by_id({ plan_id } ) - { plan_name } " ,
1795- )
1796- else :
1797- print ("ℹ️ No training plans found" )
1798- except Exception as e :
1799- print (f"❌ Error getting plan by ID: { e } " )
1802+ plan_id = int (selected ["trainingPlanId" ])
1803+ plan_name = selected .get ("name" , str (plan_id ))
1804+ plan_category = selected .get ("trainingPlanCategory" )
1805+ except ValueError :
1806+ print ("❌ Invalid plan ID" )
1807+ return
1808+ else :
1809+ selected = training_plans [- 1 ]
1810+ plan_id = int (selected ["trainingPlanId" ])
1811+ plan_name = selected .get ("name" , str (plan_id ))
1812+ plan_category = selected .get ("trainingPlanCategory" )
1813+
1814+ if plan_category == "FBT_ADAPTIVE" :
1815+ call_and_display (
1816+ api .get_adaptive_training_plan_by_id ,
1817+ plan_id ,
1818+ method_name = "get_adaptive_training_plan_by_id" ,
1819+ api_call_desc = f"api.get_adaptive_training_plan_by_id({ plan_id } ) - { plan_name } " ,
1820+ )
1821+ else :
1822+ call_and_display (
1823+ api .get_training_plan_by_id ,
1824+ plan_id ,
1825+ method_name = "get_training_plan_by_id" ,
1826+ api_call_desc = f"api.get_training_plan_by_id({ plan_id } ) - { plan_name } " ,
1827+ )
18001828
18011829
18021830def get_workout_by_id_data (api : Garmin ) -> None :
0 commit comments