Increase AquaCell timeout and handle timeout exception properly (#125263)

* Increase timeout and add handling of timeout exception

* Raise update failed instead of config entry error
pull/125420/head
Jordi 2024-09-04 23:22:31 +02:00 committed by Paulus Schoutsen
parent 84c204a7b3
commit 5c2073481d
3 changed files with 4 additions and 3 deletions

View File

@ -56,7 +56,7 @@ class AquaCellConfigFlow(ConfigFlow, domain=DOMAIN):
refresh_token = await api.authenticate(
user_input[CONF_EMAIL], user_input[CONF_PASSWORD]
)
except ApiException:
except (ApiException, TimeoutError):
errors["base"] = "cannot_connect"
except AuthenticationFailed:
errors["base"] = "invalid_auth"

View File

@ -56,7 +56,7 @@ class AquacellCoordinator(DataUpdateCoordinator[dict[str, Softener]]):
so entities can quickly look up their data.
"""
async with asyncio.timeout(10):
async with asyncio.timeout(30):
# Check if the refresh token is expired
expiry_time = (
self.refresh_token_creation_time
@ -72,7 +72,7 @@ class AquacellCoordinator(DataUpdateCoordinator[dict[str, Softener]]):
softeners = await self.aquacell_api.get_all_softeners()
except AuthenticationFailed as err:
raise ConfigEntryError from err
except AquacellApiException as err:
except (AquacellApiException, TimeoutError) as err:
raise UpdateFailed(f"Error communicating with API: {err}") from err
return {softener.dsn: softener for softener in softeners}

View File

@ -79,6 +79,7 @@ async def test_full_flow(
("exception", "error"),
[
(ApiException, "cannot_connect"),
(TimeoutError, "cannot_connect"),
(AuthenticationFailed, "invalid_auth"),
(Exception, "unknown"),
],