Skip to content

Commit

Permalink
fix: translations for default language never loaded
Browse files Browse the repository at this point in the history
feat: load translations every time config entry is set up
  • Loading branch information
alryaz committed Feb 13, 2025
1 parent 657f47d commit a180057
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions custom_components/pandora_cas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass,
language=get_config_entry_language(entry),
session=session,
ignore_recency=True,
)
except BaseException as exc:
_LOGGER.error(f"Translations download failed: {exc}", exc_info=exc)
Expand Down
15 changes: 8 additions & 7 deletions custom_components/pandora_cas/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async def async_load_web_translations(
hass: HomeAssistant,
language: str,
session: aiohttp.ClientSession | bool | None = None,
ignore_recency: bool = False,
) -> dict[str, str]:
"""Load web translations."""
if (language := language.lower()) == "last_update":
Expand Down Expand Up @@ -96,7 +97,11 @@ async def async_load_web_translations(
f"valid timestamp information."
)
else:
if (time() - last_update) > (7 * 24 * 60 * 60):
if ignore_recency:
_LOGGER.info(
f"Translation data for language {language} will be downloaded immediately."
)
elif (time() - last_update) > (7 * 24 * 60 * 60):
_LOGGER.info(
f"Last data retrieval for language {language} "
f"occurred on {datetime.fromtimestamp(last_update).isoformat()}, "
Expand All @@ -109,7 +114,7 @@ async def async_load_web_translations(
)
else:
_LOGGER.info(
f"Data for language {language} is recent, " f"no updates required."
f"Data for language {language} is recent, no updates required."
)
return saved_data[language]
else:
Expand Down Expand Up @@ -148,11 +153,7 @@ async def async_load_web_translations(
f"for language {language}, falling "
f"back to {DEFAULT_LANGUAGE}",
)
return await async_load_web_translations(
hass,
DEFAULT_LANGUAGE,
verify_ssl,
)
return await async_load_web_translations(hass, DEFAULT_LANGUAGE)

if not isinstance(language_data, dict):
saved_data[language] = language_data = {}
Expand Down

0 comments on commit a180057

Please # to comment.