Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions custom_components/reminders_api/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,32 @@ def todo_items(self) -> list[TodoItem] | None:
if (uid := self._reminder_uid(reminder))
]

def _parse_due_date(self, due_date_str: str | None) -> datetime | None:
"""Parse due date string to datetime."""
if not due_date_str:
def _parse_due_date(self, due_date_value) -> datetime | None:
if not due_date_value:
return None

if isinstance(due_date_value, dict):
due_date_value = (
due_date_value.get("iso")
or due_date_value.get("formatted")
)

if not isinstance(due_date_value, str):
_LOGGER.warning(
"Unsupported due date format: %s",
due_date_value,
)
return None

try:
return datetime.fromisoformat(due_date_str.replace("Z", "+00:00"))
except (ValueError, AttributeError):
_LOGGER.warning("Failed to parse due date: %s", due_date_str)
return datetime.fromisoformat(
due_date_value.replace("Z", "+00:00")
)
except ValueError:
_LOGGER.warning(
"Failed to parse due date: %s",
due_date_value,
)
return None

async def async_create_todo_item(self, item: TodoItem) -> None:
Expand Down Expand Up @@ -237,4 +255,4 @@ def _extract_reminder_id(self, uid: str | None) -> str:
# Handle IDs prefixed with the x-apple scheme
if uid.startswith("x-apple-reminder://"):
return uid.replace("x-apple-reminder://", "")
return uid
return uid