Add translations to Mealie exceptions (#133648)

This commit is contained in:
Joost Lekkerkerker
2024-12-20 16:08:31 +01:00
committed by GitHub
parent 87f5a7057e
commit ad7a334147
4 changed files with 37 additions and 10 deletions

View File

@@ -52,9 +52,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: MealieConfigEntry) -> bo
about = await client.get_about()
version = create_version(about.version)
except MealieAuthenticationError as error:
raise ConfigEntryAuthFailed from error
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_failed",
) from error
except MealieError as error:
raise ConfigEntryNotReady(error) from error
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="setup_failed",
) from error
if not version.valid:
LOGGER.warning(

View File

@@ -23,7 +23,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
import homeassistant.util.dt as dt_util
from .const import LOGGER
from .const import DOMAIN, LOGGER
WEEK = timedelta(days=7)
@@ -53,7 +53,7 @@ class MealieDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
super().__init__(
hass,
LOGGER,
name=self._name,
name=f"Mealie {self._name}",
update_interval=self._update_interval,
)
self.client = client
@@ -63,9 +63,15 @@ class MealieDataUpdateCoordinator[_DataT](DataUpdateCoordinator[_DataT]):
try:
return await self._async_update_internal()
except MealieAuthenticationError as error:
raise ConfigEntryAuthFailed from error
raise ConfigEntryAuthFailed(
translation_domain=DOMAIN,
translation_key="auth_failed",
) from error
except MealieConnectionError as error:
raise UpdateFailed(error) from error
raise UpdateFailed(
translation_domain=DOMAIN,
translation_key=f"update_failed_{self._name}",
) from error
@abstractmethod
async def _async_update_internal(self) -> _DataT:
@@ -77,7 +83,7 @@ class MealieMealplanCoordinator(
):
"""Class to manage fetching Mealie data."""
_name = "MealieMealplan"
_name = "mealplan"
_update_interval = timedelta(hours=1)
async def _async_update_internal(self) -> dict[MealplanEntryType, list[Mealplan]]:
@@ -106,7 +112,7 @@ class MealieShoppingListCoordinator(
):
"""Class to manage fetching Mealie Shopping list data."""
_name = "MealieShoppingList"
_name = "shopping_list"
_update_interval = timedelta(minutes=5)
async def _async_update_internal(
@@ -130,7 +136,7 @@ class MealieShoppingListCoordinator(
class MealieStatisticsCoordinator(MealieDataUpdateCoordinator[Statistics]):
"""Class to manage fetching Mealie Statistics data."""
_name = "MealieStatistics"
_name = "statistics"
_update_interval = timedelta(minutes=15)
async def _async_update_internal(

View File

@@ -61,7 +61,7 @@ rules:
comment: |
This integration does not have any irrelevant entities.
entity-translations: done
exception-translations: todo
exception-translations: done
icon-translations: done
reconfiguration-flow: done
repair-issues:

View File

@@ -126,6 +126,21 @@
},
"version_error": {
"message": "You are running {mealie_version} of Mealie. Minimum required version is {min_version}. Please upgrade Mealie and then retry."
},
"auth_failed": {
"message": "Authentication failed. Please reauthenticate."
},
"update_failed_mealplan": {
"message": "Could not fetch mealplan data."
},
"update_failed_shopping_list": {
"message": "Could not fetch shopping list data."
},
"update_failed_statistics": {
"message": "Could not fetch statistics data."
},
"setup_failed": {
"message": "Could not connect to the Mealie instance."
}
},
"services": {