From 0565ef750106fb987a76c35f03f643f624d91303 Mon Sep 17 00:00:00 2001 From: Matt Watkins <48530805+watkins-matt@users.noreply.github.com> Date: Sat, 17 Aug 2024 22:08:52 +0000 Subject: [PATCH] Filter empty items --- custom_components/google_keep_sync/todo.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/custom_components/google_keep_sync/todo.py b/custom_components/google_keep_sync/todo.py index 1a775d7..3a0dac4 100644 --- a/custom_components/google_keep_sync/todo.py +++ b/custom_components/google_keep_sync/todo.py @@ -136,7 +136,7 @@ async def async_create_todo_item(self, item: TodoItem) -> None: @property def todo_items(self) -> list[TodoItem]: - """Get the current set of To-do items.""" + """Get the current set of To-do items, filtering out empty entries.""" items = [ TodoItem( summary=item.text, @@ -148,10 +148,23 @@ def todo_items(self) -> list[TodoItem]: ), ) for item in self._gkeep_list.items + if item.text + and len(item.text.strip()) + > 0 # Filter out empty or whitespace-only entries ] + total_items = len(self._gkeep_list.items) + filtered_items = len(items) _LOGGER.debug( - "Retrieved %d todo items for list: %s", len(items), self._gkeep_list_id + "Retrieved %d todo items for list: %s", + filtered_items, + self._gkeep_list_id, ) + if filtered_items < total_items: + _LOGGER.warning( + "Filtered out %d empty items from list: %s", + total_items - filtered_items, + self._gkeep_list_id, + ) return items