Use clearCompletedTodos
API endpoint for deleting Habitica todos (#121877)
Use clearCompletedTodos endpoint for deleting multiple completed todo items
This commit is contained in:
parent
65fa4a34ed
commit
7d552b64f7
2 changed files with 16 additions and 4 deletions
|
@ -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"
|
||||
|
|
|
@ -75,14 +75,23 @@ class BaseHabiticaListEntity(HabiticaBase, TodoListEntity):
|
|||
|
||||
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()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue