Skip to content

Commit

Permalink
Add error translations to AVM Fritz!Tools (#116413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 committed Apr 29, 2024
1 parent a6fdd4e commit c595304
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
17 changes: 13 additions & 4 deletions homeassistant/components/fritz/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ async def _async_update_hosts_info(self) -> dict[str, Device]:
)
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:
Expand Down Expand Up @@ -730,7 +733,9 @@ async def service_fritzbox(
_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:
Expand Down Expand Up @@ -765,9 +770,13 @@ async def service_fritzbox(
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
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/fritz/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ async def async_call_fritz_service(service_call: ServiceCall) -> 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:
Expand Down
13 changes: 13 additions & 0 deletions homeassistant/components/fritz/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit c595304

Please sign in to comment.