Skip to content

Commit 9ea366a

Browse files
committed
Coderabbit fixes
1 parent c6846c9 commit 9ea366a

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ username = __token__
239239
password = <PyPI_API_TOKEN>
240240
```
241241

242-
# Recommended: use environment variables and restrict file perms
242+
Recommended: use environment variables and restrict file perms
243243

244244
```bash
245245
chmod 600 ~/.pypirc

garminconnect/__init__.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)