Add exception translations for IMGW-PIB integration (#140936)

Add exception translations
This commit is contained in:
Maciej Bieniek 2025-03-19 16:14:02 +01:00 committed by GitHub
parent 6211e378c3
commit 4a5567806b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -38,7 +38,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ImgwPibConfigEntry) -> b
hydrological_details=False,
)
except (ClientError, TimeoutError, ApiError) 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 = ImgwPibDataUpdateCoordinator(hass, entry, imgwpib, station_id)
await coordinator.async_config_entry_first_refresh()

View File

@ -63,4 +63,11 @@ class ImgwPibDataUpdateCoordinator(DataUpdateCoordinator[HydrologicalData]):
try:
return await self.imgwpib.get_hydrological_data()
except ApiError as err:
raise UpdateFailed(err) from err
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key="update_error",
translation_placeholders={
"entry": self.config_entry.title,
"error": repr(err),
},
) from err

View File

@ -25,5 +25,13 @@
"name": "Water temperature"
}
}
},
"exceptions": {
"cannot_connect": {
"message": "An error occurred while connecting to the IMGW-PIB API for {entry}: {error}"
},
"update_error": {
"message": "An error occurred while retrieving data from the IMGW-PIB API for {entry}: {error}"
}
}
}