Skip to content

Commit 6e0cff7

Browse files
cyberjunkyclaude
andcommitted
fix: correct get_training_readiness return type to list[dict[str, Any]]
The endpoint returns a list of snapshots, not a single dict. The wrong annotation broke downstream tooling (pydantic-validated MCP servers etc.) and caused get_morning_training_readiness to carry a dead isinstance guard. Removes the now-unnecessary isinstance(data, list) branch in get_morning_training_readiness. Closes #361 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7069111 commit 6e0cff7

1 file changed

Lines changed: 15 additions & 23 deletions

File tree

garminconnect/__init__.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ def get_hrv_data(self, cdate: str) -> dict[str, Any] | None:
16841684

16851685
return self.connectapi(url)
16861686

1687-
def get_training_readiness(self, cdate: str) -> dict[str, Any]:
1687+
def get_training_readiness(self, cdate: str) -> list[dict[str, Any]]:
16881688
"""Return training readiness data for current user."""
16891689
cdate = _validate_date_format(cdate, "cdate")
16901690
url = f"{self.garmin_connect_training_readiness_url}/{cdate}"
@@ -1717,30 +1717,22 @@ def get_morning_training_readiness(self, cdate: str) -> dict[str, Any] | None:
17171717
if not data:
17181718
return None
17191719

1720-
# If response is a list, search for morning reading
1721-
if isinstance(data, list):
1722-
# First try to find entry with AFTER_WAKEUP_RESET context
1723-
morning_entry = next(
1724-
(
1725-
entry
1726-
for entry in data
1727-
if entry.get("inputContext") == "AFTER_WAKEUP_RESET"
1728-
),
1729-
None,
1730-
)
1731-
1732-
# If no explicit morning context, return first entry as fallback
1733-
# (typically the morning reading is first in the list)
1734-
if morning_entry is None and data:
1735-
logger.debug(
1736-
"No AFTER_WAKEUP_RESET context found, using first entry as fallback"
1737-
)
1738-
return data[0]
1720+
morning_entry = next(
1721+
(
1722+
entry
1723+
for entry in data
1724+
if entry.get("inputContext") == "AFTER_WAKEUP_RESET"
1725+
),
1726+
None,
1727+
)
17391728

1740-
return morning_entry
1729+
if morning_entry is None:
1730+
logger.debug(
1731+
"No AFTER_WAKEUP_RESET context found, using first entry as fallback"
1732+
)
1733+
return data[0]
17411734

1742-
# If response is a single dict, return it directly
1743-
return data
1735+
return morning_entry
17441736

17451737
def get_endurance_score(
17461738
self, startdate: str, enddate: str | None = None

0 commit comments

Comments
 (0)