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": {
|
"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"
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Add table
Reference in a new issue