Add error translations to AVM Fritz!Tools (#116413)

This commit is contained in:
Michael 2024-04-29 20:48:54 +02:00 committed by GitHub
parent a6fdd4e1e2
commit c5953045d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 6 deletions

View File

@ -443,7 +443,10 @@ class FritzBoxTools(
) )
except Exception as ex: # pylint: disable=[broad-except] except Exception as ex: # pylint: disable=[broad-except]
if not self.hass.is_stopping: 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] = {} hosts: dict[str, Device] = {}
if hosts_attributes: if hosts_attributes:
@ -730,7 +733,9 @@ class FritzBoxTools(
_LOGGER.debug("FRITZ!Box service: %s", service_call.service) _LOGGER.debug("FRITZ!Box service: %s", service_call.service)
if not self.connection: if not self.connection:
raise HomeAssistantError("Unable to establish a connection") raise HomeAssistantError(
translation_domain=DOMAIN, translation_key="unable_to_connect"
)
try: try:
if service_call.service == SERVICE_REBOOT: if service_call.service == SERVICE_REBOOT:
@ -765,9 +770,13 @@ class FritzBoxTools(
return return
except (FritzServiceError, FritzActionError) as ex: 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: 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 class AvmWrapper(FritzBoxTools): # pylint: disable=hass-enforce-coordinator-module

View File

@ -55,8 +55,9 @@ async def async_setup_services(hass: HomeAssistant) -> None:
) )
): ):
raise HomeAssistantError( raise HomeAssistantError(
f"Failed to call service '{service_call.service}'. Config entry for" translation_domain=DOMAIN,
" target not found" translation_key="config_entry_not_found",
translation_placeholders={"service": service_call.service},
) )
for entry_id in fritzbox_entry_ids: for entry_id in fritzbox_entry_ids:

View File

@ -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"
}
} }
} }