From 1e5c6710804de9a591d87639b9585a4f987afebb Mon Sep 17 00:00:00 2001 From: Mick Date: Fri, 9 Aug 2024 22:40:52 +0000 Subject: [PATCH] Add better error handling --- custom_components/sagemcom_fast/__init__.py | 2 +- custom_components/sagemcom_fast/config_flow.py | 2 +- custom_components/sagemcom_fast/coordinator.py | 2 +- custom_components/sagemcom_fast/translations/en.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/sagemcom_fast/__init__.py b/custom_components/sagemcom_fast/__init__.py index 5a5a076..33d873d 100644 --- a/custom_components/sagemcom_fast/__init__.py +++ b/custom_components/sagemcom_fast/__init__.py @@ -75,7 +75,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): except (AuthenticationException, UnauthorizedException) as exception: LOGGER.error("Invalid_auth") raise ConfigEntryAuthFailed("Invalid credentials") from exception - except (TimeoutError, ClientError) as exception: + except (TimeoutError, ClientError, ConnectionError) as exception: LOGGER.error("Failed to connect") raise ConfigEntryNotReady("Failed to connect") from exception except MaximumSessionCountException as exception: diff --git a/custom_components/sagemcom_fast/config_flow.py b/custom_components/sagemcom_fast/config_flow.py index 1f10e8c..f500040 100644 --- a/custom_components/sagemcom_fast/config_flow.py +++ b/custom_components/sagemcom_fast/config_flow.py @@ -86,7 +86,7 @@ async def async_step_user(self, user_input=None): errors["base"] = "access_restricted" except AuthenticationException: errors["base"] = "invalid_auth" - except (TimeoutError, ClientError): + except (TimeoutError, ClientError, ConnectionError): errors["base"] = "cannot_connect" except LoginTimeoutException: errors["base"] = "login_timeout" diff --git a/custom_components/sagemcom_fast/coordinator.py b/custom_components/sagemcom_fast/coordinator.py index a5df810..c6e9204 100644 --- a/custom_components/sagemcom_fast/coordinator.py +++ b/custom_components/sagemcom_fast/coordinator.py @@ -69,7 +69,7 @@ async def _async_update_data(self) -> dict[str, Device]: raise ConfigEntryAuthFailed("Access restricted") from exception except (AuthenticationException, UnauthorizedException) as exception: raise ConfigEntryAuthFailed("Invalid credentials") from exception - except (TimeoutError, ClientError) as exception: + except (TimeoutError, ClientError, ConnectionError) as exception: raise UpdateFailed("Failed to connect") from exception except LoginRetryErrorException as exception: raise UpdateFailed( diff --git a/custom_components/sagemcom_fast/translations/en.json b/custom_components/sagemcom_fast/translations/en.json index c0f10bb..447ee1d 100644 --- a/custom_components/sagemcom_fast/translations/en.json +++ b/custom_components/sagemcom_fast/translations/en.json @@ -21,7 +21,7 @@ "ssl": "Uses an SSL certificate", "verify_ssl": "Verify SSL certificate" }, - "description": "Enter your credentials for accessing the routers web interface. Depending on the router model, Sagemcom is using different encryption methods for authentication, which can be found in the [supported devices](https://github.com/iMicknl/ha-sagemcom-fast#supported-devices) list." + "description": "Enter your credentials for accessing the router's web interface. The first login may take longer (up to a minute) as we retrieve the encryption method used by your router. For more information, see the [supported devices](https://github.com/iMicknl/ha-sagemcom-fast#supported-devices)." } } },