From e624bd5dcc7bcc5e56e3ddf3b318a860acb95c06 Mon Sep 17 00:00:00 2001 From: RogerSelwyn Date: Wed, 13 Dec 2023 10:37:17 +0000 Subject: [PATCH] feat: Add support for due date and description setting --- custom_components/o365/todo.py | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/custom_components/o365/todo.py b/custom_components/o365/todo.py index c8bf07e..be8b633 100644 --- a/custom_components/o365/todo.py +++ b/custom_components/o365/todo.py @@ -160,6 +160,8 @@ def __init__( TodoListEntityFeature.CREATE_TODO_ITEM | TodoListEntityFeature.UPDATE_TODO_ITEM | TodoListEntityFeature.DELETE_TODO_ITEM + | TodoListEntityFeature.SET_DUE_DATE_ON_ITEM + | TodoListEntityFeature.SET_DESCRIPTION_ON_ITEM ) @property @@ -261,7 +263,9 @@ def _update_extra_state_attributes(self, tasks): async def async_create_todo_item(self, item: TodoItem) -> None: """Add an item to the To-do list.""" - await self.async_new_todo(subject=item.summary) + await self.async_new_todo( + subject=item.summary, description=item.description, due=item.due + ) async def async_new_todo(self, subject, description=None, due=None, reminder=None): """Create a new task for this task list.""" @@ -375,19 +379,22 @@ async def _async_save_task(self, task, subject, description, due, reminder): task.body = description if due: - try: - if len(due) > 10: - task.due = dt.parse_datetime(due).date() - else: - task.due = dt.parse_date(due) - except ValueError: - raise ServiceValidationError( # pylint: disable=raise-missing-from - translation_domain=DOMAIN, - translation_key="due_date_invalid", - translation_placeholders={ - "due": due, - }, - ) + if isinstance(due, str): + try: + if len(due) > 10: + task.due = dt.parse_datetime(due).date() + else: + task.due = dt.parse_date(due) + except ValueError: + raise ServiceValidationError( # pylint: disable=raise-missing-from + translation_domain=DOMAIN, + translation_key="due_date_invalid", + translation_placeholders={ + "due": due, + }, + ) + else: + task.due = due if reminder: task.reminder = reminder