Skip to content

Commit

Permalink
fix Entity is not modifyable in HomeAssistant #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Craftoncu committed Mar 14, 2024
1 parent 65c982d commit 84fb26a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions custom_components/hacs_vikunja_integration/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 84fb26a

Please sign in to comment.