Skip to content

Commit

Permalink
Add error catch and bump O365 to 2.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Nov 17, 2022
1 parent 0924c29 commit 1ccb274
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion custom_components/o365/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@RogerSelwyn"
],
"requirements": [
"O365==2.0.21",
"O365==2.0.22",
"BeautifulSoup4>=4.10.0"
],
"version": "v3.3.0",
Expand Down
19 changes: 14 additions & 5 deletions custom_components/o365/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from operator import itemgetter

import requests
import voluptuous as vol
from homeassistant.const import CONF_ENABLED, CONF_NAME
from homeassistant.helpers import entity_platform
Expand Down Expand Up @@ -397,6 +398,7 @@ def __init__(self, account_name, todo):
self._id = todo.folder_id
self._name = f"{todo.name} {account_name}"
self._tasks = []
self._error = False

@property
def name(self):
Expand Down Expand Up @@ -436,11 +438,18 @@ def extra_state_attributes(self):

async def async_update(self):
"""Update state."""
data = await self.hass.async_add_executor_job( # pylint: disable=no-member
ft.partial(self._todo.get_tasks, batch=100, query=self._query)
)

self._tasks = list(data)
try:
data = await self.hass.async_add_executor_job( # pylint: disable=no-member
ft.partial(self._todo.get_tasks, batch=100, query=self._query)
)
if self._error:
_LOGGER.info("Task list reconnected for: %s", self._name)
self._error = False
self._tasks = list(data)
except requests.exceptions.HTTPError:
if not self._error:
_LOGGER.error("Task list not found for: %s", self._name)
self._error = True

def new_task(self, subject, description=None, due=None, reminder=None):
"""Create a new task for this task list."""
Expand Down

0 comments on commit 1ccb274

Please sign in to comment.