Skip to content

Commit

Permalink
maint: Capture errors from calendar retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed May 22, 2024
1 parent d23a201 commit 1cd8ae2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 12 additions & 6 deletions custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,14 +541,20 @@ def __init__(
self._error = False

async def _async_get_calendar(self, hass):
self.calendar = await hass.async_add_executor_job(
ft.partial(self._schedule.get_calendar, calendar_id=self.calendar_id)
)
try:
self.calendar = await hass.async_add_executor_job(
ft.partial(self._schedule.get_calendar, calendar_id=self.calendar_id)
)
return True
except (HTTPError, RetryError, ConnectionError) as err:
_LOGGER.warning("Error getting calendar events - %s", err)
return False

async def async_o365_get_events(self, hass, start_date, end_date):
"""Get the events."""
if not self.calendar:
await self._async_get_calendar(hass)
if not await self._async_get_calendar(hass):
return []

events = await self._async_calendar_schedule_get_events(
hass, self.calendar, start_date, end_date
Expand Down Expand Up @@ -619,8 +625,8 @@ async def _async_calendar_schedule_get_events(
include_recurring=True,
)
)
except RetryError:
_LOGGER.warning("Retry error getting calendar events")
except (HTTPError, RetryError, ConnectionError) as err:
_LOGGER.warning("Error getting calendar events - %s", err)
return None

async def async_get_events(self, hass, start_date, end_date):
Expand Down
4 changes: 4 additions & 0 deletions custom_components/o365/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"documentation": "https://github.com/RogerSelwyn/O365-HomeAssistant",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/RogerSelwyn/O365-HomeAssistant/issues",
"loggers": [
"custom_components.o365",
"O365"
],
"requirements": [
"O365==2.0.34",
"BeautifulSoup4>=4.10.0"
Expand Down

0 comments on commit 1cd8ae2

Please sign in to comment.