Fix Habitica doing blocking I/O in the event loop (#117647)

This commit is contained in:
Mr. Bubbles 2024-05-18 03:06:26 +02:00 committed by GitHub
parent 3efdeaaa77
commit 2b195cab72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -151,12 +151,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: HabiticaConfigEntry) ->
username = entry.data[CONF_API_USER] username = entry.data[CONF_API_USER]
password = entry.data[CONF_API_KEY] password = entry.data[CONF_API_KEY]
api = HAHabitipyAsync( api = await hass.async_add_executor_job(
HAHabitipyAsync,
{ {
"url": url, "url": url,
"login": username, "login": username,
"password": password, "password": password,
} },
) )
try: try:
user = await api.user.get(userFields="profile") user = await api.user.get(userFields="profile")

View File

@ -33,12 +33,13 @@ async def validate_input(hass: HomeAssistant, data: dict[str, str]) -> dict[str,
"""Validate the user input allows us to connect.""" """Validate the user input allows us to connect."""
websession = async_get_clientsession(hass) websession = async_get_clientsession(hass)
api = HabitipyAsync( api = await hass.async_add_executor_job(
conf={ HabitipyAsync,
{
"login": data[CONF_API_USER], "login": data[CONF_API_USER],
"password": data[CONF_API_KEY], "password": data[CONF_API_KEY],
"url": data[CONF_URL] or DEFAULT_URL, "url": data[CONF_URL] or DEFAULT_URL,
} },
) )
try: try:
await api.user.get(session=websession) await api.user.get(session=websession)