Use clearCompletedTodos API endpoint for deleting Habitica todos (#121877)

Use clearCompletedTodos endpoint for deleting multiple completed todo items
This commit is contained in:
Mr. Bubbles 2024-08-15 20:06:23 +02:00 committed by GitHub
parent 65fa4a34ed
commit 7d552b64f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View file

@ -100,7 +100,10 @@
}, },
"exceptions": { "exceptions": {
"delete_todos_failed": { "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": { "move_todos_item_failed": {
"message": "Unable to move the Habitica to-do to position {pos}, please try again" "message": "Unable to move the Habitica to-do to position {pos}, please try again"

View file

@ -75,6 +75,15 @@ class BaseHabiticaListEntity(HabiticaBase, TodoListEntity):
async def async_delete_todo_items(self, uids: list[str]) -> None: async def async_delete_todo_items(self, uids: list[str]) -> None:
"""Delete Habitica tasks.""" """Delete Habitica tasks."""
if len(uids) > 1 and self.entity_description.key is HabiticaTodoList.TODOS:
try:
await self.coordinator.api.tasks.clearCompletedTodos.post()
except ClientResponseError as e:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="delete_completed_todos_failed",
) from e
else:
for task_id in uids: for task_id in uids:
try: try:
await self.coordinator.api.tasks[task_id].delete() await self.coordinator.api.tasks[task_id].delete()