mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Fix language selections in workday (#145813)
This commit is contained in:
parent
95fb2a7d7f
commit
26586b4514
@ -94,21 +94,59 @@ def _get_obj_holidays(
|
|||||||
language=language,
|
language=language,
|
||||||
categories=set_categories,
|
categories=set_categories,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
supported_languages = obj_holidays.supported_languages
|
||||||
|
default_language = obj_holidays.default_language
|
||||||
|
|
||||||
|
if default_language and not language:
|
||||||
|
# If no language is set, use the default language
|
||||||
|
LOGGER.debug("Changing language from None to %s", default_language)
|
||||||
|
return country_holidays( # Return default if no language
|
||||||
|
country,
|
||||||
|
subdiv=province,
|
||||||
|
years=year,
|
||||||
|
language=default_language,
|
||||||
|
categories=set_categories,
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(supported_languages := obj_holidays.supported_languages)
|
default_language
|
||||||
and language
|
and language
|
||||||
|
and language not in supported_languages
|
||||||
and language.startswith("en")
|
and language.startswith("en")
|
||||||
):
|
):
|
||||||
|
# If language does not match supported languages, use the first English variant
|
||||||
|
if default_language.startswith("en"):
|
||||||
|
LOGGER.debug("Changing language from %s to %s", language, default_language)
|
||||||
|
return country_holidays( # Return default English if default language
|
||||||
|
country,
|
||||||
|
subdiv=province,
|
||||||
|
years=year,
|
||||||
|
language=default_language,
|
||||||
|
categories=set_categories,
|
||||||
|
)
|
||||||
for lang in supported_languages:
|
for lang in supported_languages:
|
||||||
if lang.startswith("en"):
|
if lang.startswith("en"):
|
||||||
obj_holidays = country_holidays(
|
LOGGER.debug("Changing language from %s to %s", language, lang)
|
||||||
|
return country_holidays(
|
||||||
country,
|
country,
|
||||||
subdiv=province,
|
subdiv=province,
|
||||||
years=year,
|
years=year,
|
||||||
language=lang,
|
language=lang,
|
||||||
categories=set_categories,
|
categories=set_categories,
|
||||||
)
|
)
|
||||||
LOGGER.debug("Changing language from %s to %s", language, lang)
|
|
||||||
|
if default_language and language and language not in supported_languages:
|
||||||
|
# If language does not match supported languages, use the default language
|
||||||
|
LOGGER.debug("Changing language from %s to %s", language, default_language)
|
||||||
|
return country_holidays( # Return default English if default language
|
||||||
|
country,
|
||||||
|
subdiv=province,
|
||||||
|
years=year,
|
||||||
|
language=default_language,
|
||||||
|
categories=set_categories,
|
||||||
|
)
|
||||||
|
|
||||||
return obj_holidays
|
return obj_holidays
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@ def add_province_and_language_to_schema(
|
|||||||
|
|
||||||
_country = country_holidays(country=country)
|
_country = country_holidays(country=country)
|
||||||
if country_default_language := (_country.default_language):
|
if country_default_language := (_country.default_language):
|
||||||
selectable_languages = _country.supported_languages
|
new_selectable_languages = list(_country.supported_languages)
|
||||||
new_selectable_languages = list(selectable_languages)
|
|
||||||
language_schema = {
|
language_schema = {
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_LANGUAGE, default=country_default_language
|
CONF_LANGUAGE, default=country_default_language
|
||||||
@ -154,19 +153,7 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None:
|
|||||||
years=year,
|
years=year,
|
||||||
language=language,
|
language=language,
|
||||||
)
|
)
|
||||||
if (
|
|
||||||
(supported_languages := obj_holidays.supported_languages)
|
|
||||||
and language
|
|
||||||
and language.startswith("en")
|
|
||||||
):
|
|
||||||
for lang in supported_languages:
|
|
||||||
if lang.startswith("en"):
|
|
||||||
obj_holidays = country_holidays(
|
|
||||||
country,
|
|
||||||
subdiv=province,
|
|
||||||
years=year,
|
|
||||||
language=lang,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
obj_holidays = HolidayBase(years=year)
|
obj_holidays = HolidayBase(years=year)
|
||||||
|
|
||||||
|
@ -461,3 +461,49 @@ async def test_only_repairs_for_current_next_year(
|
|||||||
|
|
||||||
assert len(issue_registry.issues) == 2
|
assert len(issue_registry.issues) == 2
|
||||||
assert issue_registry.issues == snapshot
|
assert issue_registry.issues == snapshot
|
||||||
|
|
||||||
|
|
||||||
|
async def test_missing_language(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
|
"""Test when language exist but is empty."""
|
||||||
|
config = {
|
||||||
|
"add_holidays": [],
|
||||||
|
"country": "AU",
|
||||||
|
"days_offset": 0,
|
||||||
|
"excludes": ["sat", "sun", "holiday"],
|
||||||
|
"language": None,
|
||||||
|
"name": "Workday Sensor",
|
||||||
|
"platform": "workday",
|
||||||
|
"province": "QLD",
|
||||||
|
"remove_holidays": [
|
||||||
|
"Labour Day",
|
||||||
|
],
|
||||||
|
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
||||||
|
}
|
||||||
|
await init_integration(hass, config)
|
||||||
|
assert "Changing language from None to en_AU" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_incorrect_english_variant(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
) -> None:
|
||||||
|
"""Test when language exist but is empty."""
|
||||||
|
config = {
|
||||||
|
"add_holidays": [],
|
||||||
|
"country": "AU",
|
||||||
|
"days_offset": 0,
|
||||||
|
"excludes": ["sat", "sun", "holiday"],
|
||||||
|
"language": "en_UK", # Incorrect variant
|
||||||
|
"name": "Workday Sensor",
|
||||||
|
"platform": "workday",
|
||||||
|
"province": "QLD",
|
||||||
|
"remove_holidays": [
|
||||||
|
"Labour Day",
|
||||||
|
],
|
||||||
|
"workdays": ["mon", "tue", "wed", "thu", "fri"],
|
||||||
|
}
|
||||||
|
await init_integration(hass, config)
|
||||||
|
assert "Changing language from en_UK to en_AU" in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user