From c5953045d4c40c3e665efd10066204b05bd89a3d Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 29 Apr 2024 20:48:54 +0200 Subject: [PATCH] Add error translations to AVM Fritz!Tools (#116413) --- homeassistant/components/fritz/common.py | 17 +++++++++++++---- homeassistant/components/fritz/services.py | 5 +++-- homeassistant/components/fritz/strings.json | 13 +++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index f051c824847..ec893e99ab1 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -443,7 +443,10 @@ class FritzBoxTools( ) except Exception as ex: # pylint: disable=[broad-except] if not self.hass.is_stopping: - raise HomeAssistantError("Error refreshing hosts info") from ex + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="error_refresh_hosts_info", + ) from ex hosts: dict[str, Device] = {} if hosts_attributes: @@ -730,7 +733,9 @@ class FritzBoxTools( _LOGGER.debug("FRITZ!Box service: %s", service_call.service) if not self.connection: - raise HomeAssistantError("Unable to establish a connection") + raise HomeAssistantError( + translation_domain=DOMAIN, translation_key="unable_to_connect" + ) try: if service_call.service == SERVICE_REBOOT: @@ -765,9 +770,13 @@ class FritzBoxTools( return except (FritzServiceError, FritzActionError) as ex: - raise HomeAssistantError("Service or parameter unknown") from ex + raise HomeAssistantError( + translation_domain=DOMAIN, translation_key="service_parameter_unknown" + ) from ex except FritzConnectionException as ex: - raise HomeAssistantError("Service not supported") from ex + raise HomeAssistantError( + translation_domain=DOMAIN, translation_key="service_not_supported" + ) from ex class AvmWrapper(FritzBoxTools): # pylint: disable=hass-enforce-coordinator-module diff --git a/homeassistant/components/fritz/services.py b/homeassistant/components/fritz/services.py index 47fb0ceb1c6..f0131c6bae2 100644 --- a/homeassistant/components/fritz/services.py +++ b/homeassistant/components/fritz/services.py @@ -55,8 +55,9 @@ async def async_setup_services(hass: HomeAssistant) -> None: ) ): raise HomeAssistantError( - f"Failed to call service '{service_call.service}'. Config entry for" - " target not found" + translation_domain=DOMAIN, + translation_key="config_entry_not_found", + translation_placeholders={"service": service_call.service}, ) for entry_id in fritzbox_entry_ids: diff --git a/homeassistant/components/fritz/strings.json b/homeassistant/components/fritz/strings.json index a96c3b8ac28..30603ca9032 100644 --- a/homeassistant/components/fritz/strings.json +++ b/homeassistant/components/fritz/strings.json @@ -192,5 +192,18 @@ } } } + }, + "exceptions": { + "config_entry_not_found": { + "message": "Failed to call service \"{service}\". Config entry for target not found" + }, + "service_parameter_unknown": { "message": "Service or parameter unknown" }, + "service_not_supported": { "message": "Service not supported" }, + "error_refresh_hosts_info": { + "message": "Error refreshing hosts info" + }, + "unable_to_connect": { + "message": "Unable to establish a connection" + } } }