@@ -90,6 +90,11 @@ def _fmt_ts(dt: datetime) -> str:
9090 # Use ms precision to match server expectations
9191 return dt .replace (tzinfo = None ).strftime ("%Y-%m-%dT%H:%M:%S.%f" )[:- 3 ]
9292
93+ def _validate_json_exists (response : requests .Response ) -> dict [str , Any ] | None :
94+ if response .status_code == 204 :
95+ return None
96+ return response .json ()
97+
9398
9499class Garmin :
95100 """Class for fetching data from Garmin Connect."""
@@ -677,7 +682,7 @@ def add_body_composition(
677682
678683 def add_weigh_in (
679684 self , weight : int | float , unitKey : str = "kg" , timestamp : str = ""
680- ) -> dict [str , Any ]:
685+ ) -> dict [str , Any ] | None :
681686 """Add a weigh-in (default to kg)"""
682687
683688 # Validate inputs
@@ -703,16 +708,15 @@ def add_weigh_in(
703708 "value" : weight ,
704709 }
705710 logger .debug ("Adding weigh-in" )
706-
707- return self .garth .post ("connectapi" , url , json = payload ).json ()
711+ return _validate_json_exists (self .garth .post ("connectapi" , url , json = payload ))
708712
709713 def add_weigh_in_with_timestamps (
710714 self ,
711715 weight : int | float ,
712716 unitKey : str = "kg" ,
713717 dateTimestamp : str = "" ,
714718 gmtTimestamp : str = "" ,
715- ) -> dict [str , Any ]:
719+ ) -> dict [str , Any ] | None :
716720 """Add a weigh-in with explicit timestamps (default to kg)"""
717721
718722 url = f"{ self .garmin_connect_weight_url } /user-weight"
@@ -749,7 +753,7 @@ def add_weigh_in_with_timestamps(
749753 logger .debug ("Adding weigh-in with explicit timestamps: %s" , payload )
750754
751755 # Make the POST request
752- return self .garth .post ("connectapi" , url , json = payload ). json ( )
756+ return _validate_json_exists ( self .garth .post ("connectapi" , url , json = payload ))
753757
754758 def get_weigh_ins (self , startdate : str , enddate : str ) -> dict [str , Any ]:
755759 """Get weigh-ins between startdate and enddate using format 'YYYY-MM-DD'."""
0 commit comments