From fe1328d4087730f699c2e15abdbaa74c812f4047 Mon Sep 17 00:00:00 2001 From: Jason Shiflet <387269+jshiflet@users.noreply.github.com> Date: Mon, 15 Jun 2026 22:22:38 -0500 Subject: [PATCH] Updated _parse_due_date to handle accepting a JSON dictionary object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exisitng _parse_due_date function only accepted a string as the due date. The reminders-api REST API returns a JSON dictionary object for the due date like this: ``` "dueDate" : { "formatted" : "Jul 1, 2026 at 4:00 PM CDT", "iso" : "2026-07-01T21:00:00Z", "relative" : "in 2 weeks", "timezone" : "America\/Chicago" }, ``` This update allows _parse_due_date to also accept a JSON dictionary object, and will parse the "iso" field to get the due date in a consistent format. If the dueDate value is already an ISO string, it will continue to parse it as before. Co-authored-by: codex --- custom_components/reminders_api/todo.py | 32 +++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/custom_components/reminders_api/todo.py b/custom_components/reminders_api/todo.py index b8ff326..cf0331c 100644 --- a/custom_components/reminders_api/todo.py +++ b/custom_components/reminders_api/todo.py @@ -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: @@ -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 \ No newline at end of file