Add exception translations to Renault (#187197)

This commit is contained in:
epenet
2026-10-18 20:55:18 +00:00
committed by GitHub
parent f92a1773e2
commit 340e666a17
7 changed files with 62 additions and 13 deletions
+8 -2
View File
@@ -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)
@@ -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
@@ -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
@@ -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)
@@ -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
+22 -1
View File
@@ -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": {
+2 -1
View File
@@ -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] == ()