Skip to content

Commit

Permalink
Fixed small issue with completing the tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemysław Szafrański committed Jan 21, 2025
1 parent b36a28b commit 15916fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/ticktick/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"issue_tracker": "/~https://github.com/Hantick/ticktick-home-assistant/issues",
"requirements": [],
"ssdp": [],
"version": "2.0.7",
"version": "2.0.8",
"zeroconf": []
}
19 changes: 10 additions & 9 deletions custom_components/ticktick/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def _map_task(
"""Convert a TodoItem to Task."""
modified = False
if api_task:
if item.summary != api_task.title:
if (item.summary or "").strip() != (api_task.title or "").strip():
api_task.title = item.summary
modified = True
if item.description != api_task.content:
if (item.description or "").strip() != (api_task.content or "").strip():
api_task.content = item.description
modified = True
if item.due != api_task.dueDate:
if (item.due or "").strip() != (api_task.dueDate or "").strip():
api_task.dueDate = item.due
modified = True
return api_task, modified
Expand Down Expand Up @@ -125,7 +125,7 @@ async def async_create_todo_item(self, item: TodoItem) -> None:
async def async_update_todo_item(self, item: TodoItem) -> None:
"""Update a To-do item."""

async def process_status_change() -> None:
async def process_status_change() -> bool:
if item.status is not None:
# Only update status if changed
for existing_item in self._attr_todo_items or ():
Expand All @@ -137,8 +137,10 @@ async def process_status_change() -> None:
await self.coordinator.api.complete_task(
projectId=self._project_id, taskId=item.uid
)
return True
# else:
# Not supported by TickTick as they don't return completed tasks
return False

projects_with_tasks = self.coordinator.data
api_task = next(
Expand All @@ -152,15 +154,14 @@ async def process_status_change() -> None:
None,
)

if await process_status_change(): # This should be changed if completing the task will support also changing description etc.
await self.coordinator.async_refresh()
return

mapped_task, is_modified = _map_task(item, self._project_id, api_task)

updated = False
if is_modified:
await self.coordinator.api.update_task(mapped_task)
updated = True

if not updated:
await process_status_change()

await self.coordinator.async_refresh()

Expand Down

0 comments on commit 15916fd

Please sign in to comment.