Skip to content

Commit

Permalink
Use clearCompletedTodos API endpoint for deleting Habitica todos (#…
Browse files Browse the repository at this point in the history
…121877)

Use clearCompletedTodos endpoint for deleting multiple completed todo items
tr4nt0r authored Aug 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 65fa4a3 commit 7d552b6
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion homeassistant/components/habitica/strings.json
Original file line number Diff line number Diff line change
@@ -100,7 +100,10 @@
},
"exceptions": {
"delete_todos_failed": {
"message": "Unable to delete {count} Habitica to-do(s), please try again"
"message": "Unable to delete item from Habitica to-do list, please try again"
},
"delete_completed_todos_failed": {
"message": "Unable to delete completed to-do items from Habitica to-do list, please try again"
},
"move_todos_item_failed": {
"message": "Unable to move the Habitica to-do to position {pos}, please try again"
15 changes: 12 additions & 3 deletions homeassistant/components/habitica/todo.py
Original file line number Diff line number Diff line change
@@ -75,14 +75,23 @@ def __init__(

async def async_delete_todo_items(self, uids: list[str]) -> None:
"""Delete Habitica tasks."""
for task_id in uids:
if len(uids) > 1 and self.entity_description.key is HabiticaTodoList.TODOS:
try:
await self.coordinator.api.tasks[task_id].delete()
await self.coordinator.api.tasks.clearCompletedTodos.post()
except ClientResponseError as e:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key=f"delete_{self.entity_description.key}_failed",
translation_key="delete_completed_todos_failed",
) from e
else:
for task_id in uids:
try:
await self.coordinator.api.tasks[task_id].delete()
except ClientResponseError as e:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key=f"delete_{self.entity_description.key}_failed",
) from e

await self.coordinator.async_refresh()

0 comments on commit 7d552b6

Please sign in to comment.