From 84fb26a3c7cc4ab6b3c3557044987e459fcc82b2 Mon Sep 17 00:00:00 2001 From: Daniel Kollmannsberger Date: Thu, 14 Mar 2024 03:19:05 +0000 Subject: [PATCH] fix Entity is not modifyable in HomeAssistant #10 --- .../hacs_vikunja_integration/todo.py | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/custom_components/hacs_vikunja_integration/todo.py b/custom_components/hacs_vikunja_integration/todo.py index e753d22..b10bfb9 100644 --- a/custom_components/hacs_vikunja_integration/todo.py +++ b/custom_components/hacs_vikunja_integration/todo.py @@ -48,21 +48,28 @@ def _convert_todo_item(item: TodoItem) -> dict[str, str | None]: def _convert_api_item(item: dict[str, str]) -> TodoItem: """Convert tasks API items into a TodoItem.""" - due: date | None = None - if (due_str := item.get("due")) is not None: - due = datetime.fromisoformat(due_str).date() + + + due: date | datetime | None = None + due_str = item.get("due_date") + if due_str and due_str != "0001-01-01T00:00:00Z": # due to vikunja response if no due date is set + try: + due = datetime.fromisoformat(due_str) + except ValueError: + due = None + + status = TodoItemStatus.COMPLETED if item.get("done", False) else TodoItemStatus.NEEDS_ACTION + return TodoItem( summary=item["title"], uid=str(item["id"]), - status=TODO_STATUS_MAP.get( - item.get("status", ""), - TodoItemStatus.NEEDS_ACTION, - ), + status=status, due=due, - description=item.get("notes"), + description=item["description"], ) + async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: