@@ -537,10 +537,12 @@ def get_heart_rates(self, cdate: str) -> dict[str, Any]:
537537 def get_stats_and_body (self , cdate : str ) -> dict [str , Any ]:
538538 """Return activity data and body composition (compat for garminconnect)."""
539539
540- return {
541- ** self .get_stats (cdate ),
542- ** self .get_body_composition (cdate )["totalAverage" ],
543- }
540+ stats = self .get_stats (cdate )
541+ body = self .get_body_composition (cdate )
542+ body_avg = body .get ("totalAverage" ) or {}
543+ if not isinstance (body_avg , dict ):
544+ body_avg = {}
545+ return {** stats , ** body_avg }
544546
545547 def get_body_composition (
546548 self , startdate : str , enddate : str | None = None
@@ -654,13 +656,20 @@ def add_weigh_in_with_timestamps(
654656
655657 if unitKey not in VALID_WEIGHT_UNITS :
656658 raise ValueError (f"unitKey must be one of { VALID_WEIGHT_UNITS } " )
657- # Validate and format the timestamps
658- dt = datetime .fromisoformat (dateTimestamp ) if dateTimestamp else datetime .now ()
659- dtGMT = (
660- datetime .fromisoformat (gmtTimestamp )
661- if gmtTimestamp
662- else dt .astimezone (timezone .utc )
659+ # Make local timestamp timezone-aware
660+ dt = (
661+ datetime .fromisoformat (dateTimestamp ).astimezone ()
662+ if dateTimestamp
663+ else datetime .now ().astimezone ()
663664 )
665+ if gmtTimestamp :
666+ g = datetime .fromisoformat (gmtTimestamp )
667+ # Assume provided GMT is UTC if naive; otherwise convert to UTC
668+ if g .tzinfo is None :
669+ g = g .replace (tzinfo = timezone .utc )
670+ dtGMT = g .astimezone (timezone .utc )
671+ else :
672+ dtGMT = dt .astimezone (timezone .utc )
664673
665674 # Validate weight for consistency with add_weigh_in
666675 weight = _validate_positive_number (weight , "weight" )
@@ -2020,7 +2029,7 @@ def upload_workout(
20202029 raise ValueError (f"invalid workout_json string: { e } " ) from e
20212030 else :
20222031 payload = workout_json
2023- if not isinstance (payload , ( dict | list ) ):
2032+ if not isinstance (payload , dict | list ):
20242033 raise ValueError ("workout_json must be a JSON object or array" )
20252034 return self .garth .post ("connectapi" , url , json = payload , api = True ).json ()
20262035
0 commit comments