From 54cb00217701a70f62e4b890facb5316f42f9b24 Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Fri, 9 Dec 2022 08:19:01 +0000 Subject: [PATCH] Incorporate conflicting changes --- custom_components/o365/classes/taskssensor.py | 16 +++++++++++----- custom_components/o365/sensor.py | 7 ++++++- custom_components/o365/utils.py | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/custom_components/o365/classes/taskssensor.py b/custom_components/o365/classes/taskssensor.py index d65a418..c36d904 100644 --- a/custom_components/o365/classes/taskssensor.py +++ b/custom_components/o365/classes/taskssensor.py @@ -7,6 +7,7 @@ ATTR_ALL_TASKS, ATTR_DUE, ATTR_OVERDUE_TASKS, + ATTR_REMINDER, ATTR_SUBJECT, ATTR_TASKS, CONF_CONFIG_TYPE, @@ -41,11 +42,16 @@ def extra_state_attributes(self): for item in self.coordinator.data[self.entity_id][ATTR_TASKS]: task = {ATTR_SUBJECT: item.subject} if item.due: - task[ATTR_DUE] = item.due - if item.due < dt.utcnow(): - overdue_tasks.append( - {ATTR_SUBJECT: item.subject, ATTR_DUE: item.due} - ) + due = item.due.date() + task[ATTR_DUE] = due + if due < dt.utcnow().date(): + overdue_task = {ATTR_SUBJECT: item.subject, ATTR_DUE: due} + if item.is_reminder_on: + overdue_task[ATTR_REMINDER] = item.reminder + overdue_tasks.append(overdue_task) + + if item.is_reminder_on: + task[ATTR_REMINDER] = item.reminder all_tasks.append(task) diff --git a/custom_components/o365/sensor.py b/custom_components/o365/sensor.py index f932a21..d06d573 100644 --- a/custom_components/o365/sensor.py +++ b/custom_components/o365/sensor.py @@ -309,13 +309,18 @@ async def _async_email_update(self, entity): download_attachments=entity.download_attachments, ) ) - attrs = [get_email_attributes(x, entity.download_attachments) for x in data] + attrs = await self.hass.async_add_executor_job( # pylint: disable=no-member + self._get_attributes, data, entity + ) attrs.sort(key=itemgetter("received"), reverse=True) self._data[entity.entity_id] = { ATTR_STATE: len(attrs), ATTR_ATTRIBUTES: {"data": attrs}, } + def _get_attributes(self, data, entity): + return [get_email_attributes(x, entity.download_attachments) for x in data] + async def _async_teams_status_update(self, entity): """Update state.""" if data := await self.hass.async_add_executor_job(entity.teams.get_my_presence): diff --git a/custom_components/o365/utils.py b/custom_components/o365/utils.py index b2d359d..ed29144 100644 --- a/custom_components/o365/utils.py +++ b/custom_components/o365/utils.py @@ -10,9 +10,10 @@ import yaml from bs4 import BeautifulSoup from homeassistant.const import CONF_ENABLED, CONF_NAME -from O365.calendar import Attendee # pylint: disable=no-name-in-module) from voluptuous.error import Error as VoluptuousError +from O365.calendar import Attendee # pylint: disable=no-name-in-module) + from .const import ( CONF_ACCOUNT_NAME, CONF_CAL_ID,