From 68660eb213844476dca3cc0fd334ba7aef439dff Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Mon, 25 Mar 2024 09:26:29 +0000 Subject: [PATCH] fix: Enable clearing of ToDo description from HA ToDo panel https://github.com/RogerSelwyn/O365-HomeAssistant/issues/215 --- custom_components/o365/todo.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/custom_components/o365/todo.py b/custom_components/o365/todo.py index e146652..cb0c480 100644 --- a/custom_components/o365/todo.py +++ b/custom_components/o365/todo.py @@ -304,8 +304,8 @@ async def async_update_todo_item(self, item: TodoItem) -> None: self.todolist.get_task, item.uid ) if ( - (item.summary and item.summary != o365_task.subject) - or (item.description and item.description != o365_task.body) + item.summary != o365_task.subject + or item.description != o365_task.body or (item.due and item.due != o365_task.due) ): await self.async_update_todo( @@ -314,6 +314,7 @@ async def async_update_todo_item(self, item: TodoItem) -> None: description=item.description, due=item.due, o365_task=o365_task, + hatodo=True, ) if item.status: completed = None @@ -332,6 +333,7 @@ async def async_update_todo( due=None, reminder=None, o365_task=None, + hatodo=False, ): """Update a task for this task list.""" if not self._validate_task_permissions(): @@ -341,7 +343,9 @@ async def async_update_todo( o365_task = await self.hass.async_add_executor_job( self.todolist.get_task, todo_id ) - await self._async_save_task(o365_task, subject, description, due, reminder) + await self._async_save_task( + o365_task, subject, description, due, reminder, hatodo + ) self._raise_event(EVENT_UPDATE_TODO, todo_id) await self.coordinator.async_refresh() return True @@ -402,11 +406,13 @@ async def _async_uncomplete_task(self, o365_task, todo_id): self.hass.async_add_executor_job(o365_task.save) self._raise_event(EVENT_UNCOMPLETED_TODO, todo_id) - async def _async_save_task(self, o365_task, subject, description, due, reminder): + async def _async_save_task( + self, o365_task, subject, description, due, reminder, hatodo=False + ): # sourcery skip: raise-from-previous-error - if subject: + if subject or hatodo: o365_task.subject = subject - if description: + if description or hatodo: o365_task.body = description if due: