Reduce API calls to fetch Habitica tasks (#116897)
This commit is contained in:
parent
7e8fab65ff
commit
d81fad1ef1
2 changed files with 16 additions and 18 deletions
|
@ -47,9 +47,7 @@ class HabiticaDataUpdateCoordinator(DataUpdateCoordinator[HabiticaData]):
|
|||
|
||||
try:
|
||||
user_response = await self.api.user.get(userFields=",".join(user_fields))
|
||||
tasks_response = []
|
||||
for task_type in ("todos", "dailys", "habits", "rewards"):
|
||||
tasks_response.extend(await self.api.tasks.user.get(type=task_type))
|
||||
tasks_response = await self.api.tasks.user.get()
|
||||
except ClientResponseError as error:
|
||||
raise UpdateFailed(f"Error communicating with API: {error}") from error
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ from homeassistant.components.habitica.const import (
|
|||
EVENT_API_CALL_SUCCESS,
|
||||
SERVICE_API_CALL,
|
||||
)
|
||||
from homeassistant.components.habitica.sensor import TASKS_TYPES
|
||||
from homeassistant.const import ATTR_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
@ -73,20 +72,21 @@ def common_requests(aioclient_mock):
|
|||
}
|
||||
},
|
||||
)
|
||||
for n_tasks, task_type in enumerate(TASKS_TYPES.keys(), start=1):
|
||||
aioclient_mock.get(
|
||||
f"https://habitica.com/api/v3/tasks/user?type={task_type}",
|
||||
json={
|
||||
"data": [
|
||||
{
|
||||
"text": f"this is a mock {task_type} #{task}",
|
||||
"id": f"{task}",
|
||||
"type": TASKS_TYPES[task_type].path[0],
|
||||
}
|
||||
for task in range(n_tasks)
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
aioclient_mock.get(
|
||||
"https://habitica.com/api/v3/tasks/user",
|
||||
json={
|
||||
"data": [
|
||||
{
|
||||
"text": f"this is a mock {task} #{i}",
|
||||
"id": f"{i}",
|
||||
"type": task,
|
||||
"completed": False,
|
||||
}
|
||||
for i, task in enumerate(("habit", "daily", "todo", "reward"), start=1)
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
aioclient_mock.post(
|
||||
"https://habitica.com/api/v3/tasks/user",
|
||||
|
|
Loading…
Add table
Reference in a new issue