Add exception translations for GIOS integration (#141006)

Add exception translations
pull/141011/head
Maciej Bieniek 2025-03-20 16:58:49 +01:00 committed by GitHub
parent a835c85f59
commit 70ed120c6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -44,7 +44,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: GiosConfigEntry) -> bool
try:
gios = await Gios.create(websession, station_id)
except (GiosError, ConnectionError, ClientConnectorError) as err:
raise ConfigEntryNotReady from err
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="cannot_connect",
translation_placeholders={
"entry": entry.title,
"error": repr(err),
},
) from err
coordinator = GiosDataUpdateCoordinator(hass, entry, gios)
await coordinator.async_config_entry_first_refresh()

View File

@ -57,4 +57,11 @@ class GiosDataUpdateCoordinator(DataUpdateCoordinator[GiosSensors]):
async with asyncio.timeout(API_TIMEOUT):
return await self.gios.async_update()
except (GiosError, ClientConnectorError) as error:
raise UpdateFailed(error) from error
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="update_error",
translation_placeholders={
"entry": self.config_entry.title,
"error": repr(error),
},
) from error

View File

@ -170,5 +170,13 @@
}
}
}
},
"exceptions": {
"cannot_connect": {
"message": "An error occurred while connecting to the GIOS API for {entry}: {error}"
},
"update_error": {
"message": "An error occurred while retrieving data from the GIOS API for {entry}: {error}"
}
}
}