From b91b1fd319319bca703614c6de14154ecccba14d Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Mon, 30 Oct 2023 11:35:43 +0000 Subject: [PATCH 1/2] fix: Fix invalid task handling --- custom_components/o365/classes/taskssensor.py | 1 - custom_components/o365/manifest.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/o365/classes/taskssensor.py b/custom_components/o365/classes/taskssensor.py index 3f165f8..6fc1216 100644 --- a/custom_components/o365/classes/taskssensor.py +++ b/custom_components/o365/classes/taskssensor.py @@ -79,7 +79,6 @@ def _handle_coordinator_update(self) -> None: self._state = len(tasks) self._extra_attributes = self._update_extra_state_attributes(tasks) - tasks = self.coordinator.data[self.entity_key][ATTR_TASKS] task_last_completed = self._zero_date task_last_created = self._zero_date for task in tasks: diff --git a/custom_components/o365/manifest.json b/custom_components/o365/manifest.json index 0457c29..3aec725 100644 --- a/custom_components/o365/manifest.json +++ b/custom_components/o365/manifest.json @@ -15,5 +15,5 @@ "O365==2.0.28", "BeautifulSoup4>=4.10.0" ], - "version": "v4.4.3b1" + "version": "v4.4.3b2" } \ No newline at end of file From 3da9de825dc24fe1a55c52aa63d02d9ecbcc8d9c Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Mon, 30 Oct 2023 16:21:40 +0000 Subject: [PATCH 2/2] maint: Add warning indicating corrupt token --- custom_components/o365/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/custom_components/o365/__init__.py b/custom_components/o365/__init__.py index 7536481..e658122 100644 --- a/custom_components/o365/__init__.py +++ b/custom_components/o365/__init__.py @@ -1,6 +1,7 @@ """Main initialisation code.""" import copy import functools as ft +import json import logging import os import shutil @@ -8,9 +9,8 @@ import yaml from homeassistant.const import CONF_ENABLED from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from oauthlib.oauth2.rfc6749.errors import InvalidClientError - from O365 import Account, FileSystemTokenBackend +from oauthlib.oauth2.rfc6749.errors import InvalidClientError from .classes.permissions import Permissions from .const import ( @@ -151,7 +151,15 @@ async def _async_setup_account(hass, account_conf, conf_type): main_resource=main_resource, ) ) - is_authenticated = account.is_authenticated + try: + is_authenticated = account.is_authenticated + except json.decoder.JSONDecodeError as err: + _LOGGER.warning( + "Token corrupt for account - please delete and re-authenticate: %s. Error - %s", + account_name, + err, + ) + return permissions, failed_permissions = perms.validate_permissions() check_token = None