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>pull/124569/head
parent
1bdf9d657e
commit
a45c1a3914
|
@ -49,7 +49,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:
|
||||
raise UpdateFailed(f"Error communicating with API: {error}") from error
|
||||
|
||||
|
|
|
@ -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…
Reference in New Issue