Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,15 @@ def __init__(self):
},
},
},
"d": {
"name": "📅 Calendar",
"options": {
"1": {
"desc": f"Get calendar items for '{config.month_start.month}/{config.month_start.year}'",
"key": "get_calendar_data",
}
},
},
}

current_category = None
Expand Down Expand Up @@ -4174,6 +4183,13 @@ def execute_api_call(api: Garmin, key: str) -> None:
"disconnect": lambda: disconnect_api(api),
# GraphQL Queries
"query_garmin_graphql": lambda: query_garmin_graphql_data(api),
"get_calendar_data": lambda: call_and_display(
api.get_calendar_data,
config.month_start.year,
config.month_start.month,
method_name="get_calendar_data",
api_call_desc=f"api.get_calendar_data({config.month_start.year}, {config.month_start.month})",
),
}

if key in api_methods:
Expand Down
23 changes: 23 additions & 0 deletions garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def __init__(
"/lifestylelogging-service/dailyLog"
)

self.garmin_connect_calendar = "/calendar-service"

self.client = client.Client(
domain="garmin.cn" if is_cn else "garmin.com",
pool_connections=20,
Expand Down Expand Up @@ -2926,6 +2928,27 @@ def get_golf_shot_data(
)
return self.connectapi(url, params=params)

def get_calendar_data(
self,
year: int,
month: int,
) -> dict[str, Any]:
"""Fetch calendar items for year and month.
:param year: year to retrieve items for
:type year: int
:param month: month to retrieve
:type month: int
:return: dictionary containing metadata and a list of the calendar items.
"""
year = _validate_positive_integer(year, "year")
month = _validate_positive_integer(month, "month")
if month < 1 or month > 12:
raise ValueError(f"month must be between 1 and 12, got: {month}")

url = f"{self.garmin_connect_calendar}/year/{year}/month/{month}"
logger.debug("Requesting calendar items.")
return self.connectapi(url)


from .exceptions import ( # noqa: E402
GarminConnectAuthenticationError,
Expand Down
2 changes: 1 addition & 1 deletion garminconnect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _portal_web_login_cffi(
for imp in impersonations:
try:
_LOGGER.debug("Trying portal+cffi with impersonation=%s", imp)
sess: Any = cffi_requests.Session(impersonate=imp) # type: ignore[arg-type]
sess: Any = cffi_requests.Session(impersonate=imp)
return self._portal_web_login(
sess,
email,
Expand Down