Fix missing id in Habitica completed todos API response (#124565)
* Fix missing id in completed todos API response * Copy id only if none * Update homeassistant/components/habitica/coordinator.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> --------- Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
5550b1a74e
commit
c9e7c76ee5
2 changed files with 22 additions and 15 deletions
|
@ -56,7 +56,14 @@ class HabiticaDataUpdateCoordinator(DataUpdateCoordinator[HabiticaData]):
|
|||
try:
|
||||
user_response = await self.api.user.get()
|
||||
tasks_response = await self.api.tasks.user.get()
|
||||
tasks_response.extend(await self.api.tasks.user.get(type="completedTodos"))
|
||||
tasks_response.extend(
|
||||
[
|
||||
{"id": task["_id"], **task}
|
||||
for task in await self.api.tasks.user.get(type="completedTodos")
|
||||
if task.get("_id")
|
||||
]
|
||||
)
|
||||
|
||||
except ClientResponseError as error:
|
||||
if error.status == HTTPStatus.TOO_MANY_REQUESTS:
|
||||
_LOGGER.debug("Currently rate limited, skipping update")
|
||||
|
|
|
@ -73,7 +73,20 @@ def common_requests(aioclient_mock: AiohttpClientMocker) -> AiohttpClientMocker:
|
|||
}
|
||||
},
|
||||
)
|
||||
|
||||
aioclient_mock.get(
|
||||
"https://habitica.com/api/v3/tasks/user?type=completedTodos",
|
||||
json={
|
||||
"data": [
|
||||
{
|
||||
"text": "this is a mock todo #5",
|
||||
"id": 5,
|
||||
"_id": 5,
|
||||
"type": "todo",
|
||||
"completed": True,
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
aioclient_mock.get(
|
||||
"https://habitica.com/api/v3/tasks/user",
|
||||
json={
|
||||
|
@ -88,19 +101,6 @@ def common_requests(aioclient_mock: AiohttpClientMocker) -> AiohttpClientMocker:
|
|||
]
|
||||
},
|
||||
)
|
||||
aioclient_mock.get(
|
||||
"https://habitica.com/api/v3/tasks/user?type=completedTodos",
|
||||
json={
|
||||
"data": [
|
||||
{
|
||||
"text": "this is a mock todo #5",
|
||||
"id": 5,
|
||||
"type": "todo",
|
||||
"completed": True,
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
aioclient_mock.post(
|
||||
"https://habitica.com/api/v3/tasks/user",
|
||||
|
|
Loading…
Add table
Reference in a new issue