From 340e666a17d970fc03d25cf908d7a727239d6557 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:55:18 +0200 Subject: [PATCH] Add exception translations to Renault (#187197) --- homeassistant/components/renault/__init__.py | 10 ++++-- .../components/renault/coordinator.py | 32 +++++++++++++++---- .../components/renault/quality_scale.yaml | 2 +- .../components/renault/renault_hub.py | 4 ++- .../components/renault/renault_vehicle.py | 1 - homeassistant/components/renault/strings.json | 23 ++++++++++++- tests/components/renault/test_services.py | 3 +- 7 files changed, 62 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/renault/__init__.py b/homeassistant/components/renault/__init__.py index c621f7f3f974..f94aeac7eebb 100644 --- a/homeassistant/components/renault/__init__.py +++ b/homeassistant/components/renault/__init__.py @@ -46,7 +46,10 @@ async def async_setup_entry( try: await renault_hub.async_initialise(config_entry) except NotAuthenticatedException as exc: - raise ConfigEntryAuthFailed from exc + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="authentication_failed", + ) from exc except ForbiddenException as exc: account_id = config_entry.data[RenaultConfigurationKeys.KAMEREON_ACCOUNT_ID] if account_id not in await renault_hub.get_all_account_ids(): @@ -67,7 +70,10 @@ async def async_setup_entry( translation_placeholders={"account_id": account_id}, ) from exc except (aiohttp.ClientError, GigyaException) as exc: - raise ConfigEntryNotReady from exc + raise ConfigEntryNotReady( + translation_domain=DOMAIN, + translation_key="cannot_connect", + ) from exc ir.async_delete_issue( hass, DOMAIN, _account_not_found_issue_id(config_entry.entry_id) diff --git a/homeassistant/components/renault/coordinator.py b/homeassistant/components/renault/coordinator.py index 221f952ac308..363a07fc4964 100644 --- a/homeassistant/components/renault/coordinator.py +++ b/homeassistant/components/renault/coordinator.py @@ -19,6 +19,8 @@ from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed +from .const import DOMAIN + if TYPE_CHECKING: from . import RenaultConfigEntry from .renault_hub import RenaultHub @@ -68,7 +70,10 @@ class RenaultDataUpdateCoordinator[T: KamereonVehicleDataAttributes]( if self._hub.is_throttled(): if not self._has_already_worked: - raise UpdateFailed("Renault hub currently throttled: init skipped") + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="throttled", + ) # we have been throttled and decided to cooldown # so do not count this update as an error # coordinator. last_update_success should still be ok @@ -86,7 +91,10 @@ class RenaultDataUpdateCoordinator[T: KamereonVehicleDataAttributes]( if not self._has_already_worked: self.update_interval = None self.access_denied = True - raise UpdateFailed(f"This endpoint is denied: {err}") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="endpoint_denied", + ) from err except QuotaLimitException as err: # The data we got is not bad per see, initiate cooldown for all coordinators @@ -96,20 +104,32 @@ class RenaultDataUpdateCoordinator[T: KamereonVehicleDataAttributes]( self.logger.warning("Renault API throttled") return self.data - raise UpdateFailed(f"Renault API throttled: {err}") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="throttled", + ) from err except NotSupportedException as err: # Disable because the vehicle does not support this Renault endpoint. self.update_interval = None self.not_supported = True - raise UpdateFailed(f"This endpoint is not supported: {err}") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="endpoint_not_supported", + ) from err except NotAuthenticatedException as err: - raise ConfigEntryAuthFailed from err + raise ConfigEntryAuthFailed( + translation_domain=DOMAIN, + translation_key="authentication_expired", + ) from err except KamereonResponseException as err: # Other Renault errors. - raise UpdateFailed(f"Error communicating with API: {err}") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="communication_error", + ) from err self._has_already_worked = True self.assumed_state = False diff --git a/homeassistant/components/renault/quality_scale.yaml b/homeassistant/components/renault/quality_scale.yaml index 56567469b669..e29fe278377d 100644 --- a/homeassistant/components/renault/quality_scale.yaml +++ b/homeassistant/components/renault/quality_scale.yaml @@ -58,7 +58,7 @@ rules: entity-device-class: done entity-disabled-by-default: done entity-translations: done - exception-translations: todo + exception-translations: done icon-translations: done reconfiguration-flow: done repair-issues: done diff --git a/homeassistant/components/renault/renault_hub.py b/homeassistant/components/renault/renault_hub.py index 0b8fc3308ee4..037bcc5d64f4 100644 --- a/homeassistant/components/renault/renault_hub.py +++ b/homeassistant/components/renault/renault_hub.py @@ -25,6 +25,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import ( COOLING_UPDATES_SECONDS, + DOMAIN, MAX_CALLS_PER_HOURS, RenaultConfigurationKeys, ) @@ -168,7 +169,8 @@ class RenaultHub: "No valid vehicle details found for account_id: %s", account_id ) raise ConfigEntryNotReady( - "Failed to retrieve vehicle details from Renault servers" + translation_domain=DOMAIN, + translation_key="no_vehicle_details", ) num_call_per_scan = len(COORDINATORS) * len(vehicle_links) diff --git a/homeassistant/components/renault/renault_vehicle.py b/homeassistant/components/renault/renault_vehicle.py index 52363c61a9f5..fed24db21013 100644 --- a/homeassistant/components/renault/renault_vehicle.py +++ b/homeassistant/components/renault/renault_vehicle.py @@ -50,7 +50,6 @@ def with_error_wrapping[**_P, _R]( raise HomeAssistantError( translation_domain=DOMAIN, translation_key="unknown_error", - translation_placeholders={"error": str(err)}, ) from err return wrapper diff --git a/homeassistant/components/renault/strings.json b/homeassistant/components/renault/strings.json index 499dcd7a123d..ac0232c2ec82 100644 --- a/homeassistant/components/renault/strings.json +++ b/homeassistant/components/renault/strings.json @@ -240,14 +240,35 @@ "authentication_expired": { "message": "The Renault login has expired, re-authenticate the Renault integration" }, + "authentication_failed": { + "message": "Failed to log in to the Renault servers, re-authenticate the Renault integration" + }, "battery_soc_unavailable": { "message": "Battery state of charge data is currently unavailable" }, + "cannot_connect": { + "message": "Failed to connect to the Renault servers" + }, + "communication_error": { + "message": "An error occurred while communicating with the Renault servers" + }, + "endpoint_denied": { + "message": "Access to this data was denied by the Renault servers" + }, + "endpoint_not_supported": { + "message": "This data is not supported by the vehicle" + }, "no_config_entry_for_device": { "message": "No loaded config entry was found for device with ID {device_id}" }, + "no_vehicle_details": { + "message": "Failed to retrieve vehicle details from the Renault servers" + }, + "throttled": { + "message": "The Renault servers are throttling requests" + }, "unknown_error": { - "message": "An unknown error occurred while communicating with the Renault servers: {error}" + "message": "An unknown error occurred while communicating with the Renault servers" } }, "issues": { diff --git a/tests/components/renault/test_services.py b/tests/components/renault/test_services.py index 4508579cf3e3..25909b6da290 100644 --- a/tests/components/renault/test_services.py +++ b/tests/components/renault/test_services.py @@ -471,10 +471,11 @@ async def test_service_exception( "renault_api.renault_vehicle.RenaultVehicle.set_ac_stop", side_effect=RenaultException("Didn't work"), ) as mock_action, - pytest.raises(HomeAssistantError, match="Didn't work"), + pytest.raises(HomeAssistantError) as err, ): await hass.services.async_call( DOMAIN, RenaultService.AC_CANCEL, service_data=data, blocking=True ) + assert err.value.translation_key == "unknown_error" assert len(mock_action.mock_calls) == 1 assert mock_action.mock_calls[0][1] == ()