Skip to content

Commit

Permalink
feat: Add support for due date and description setting
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Dec 13, 2023
1 parent 4292e46 commit e624bd5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions custom_components/o365/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e624bd5

Please sign in to comment.