Fix language flavors in holiday (#107392)
parent
d260ed938a
commit
d8c139f211
|
@ -43,6 +43,18 @@ async def async_setup_entry(
|
|||
)
|
||||
language = lang
|
||||
break
|
||||
if (
|
||||
obj_holidays.supported_languages
|
||||
and language not in obj_holidays.supported_languages
|
||||
and (default_language := obj_holidays.default_language)
|
||||
):
|
||||
obj_holidays = country_holidays(
|
||||
country,
|
||||
subdiv=province,
|
||||
years={dt_util.now().year, dt_util.now().year + 1},
|
||||
language=default_language,
|
||||
)
|
||||
language = default_language
|
||||
|
||||
async_add_entities(
|
||||
[
|
||||
|
|
|
@ -227,3 +227,88 @@ async def test_no_next_event(
|
|||
assert state is not None
|
||||
assert state.state == "off"
|
||||
assert state.attributes == {"friendly_name": "Germany"}
|
||||
|
||||
|
||||
async def test_language_not_exist(
|
||||
hass: HomeAssistant, freezer: FrozenDateTimeFactory
|
||||
) -> None:
|
||||
"""Test when language doesn't exist it will fallback to country default language."""
|
||||
|
||||
hass.config.language = "nb" # Norweigan language "Norks bokmål"
|
||||
hass.config.country = "NO"
|
||||
|
||||
freezer.move_to(datetime(2023, 1, 1, 12, tzinfo=dt_util.UTC))
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={CONF_COUNTRY: "NO"},
|
||||
title="Norge",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("calendar.norge")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
assert state.attributes == {
|
||||
"friendly_name": "Norge",
|
||||
"all_day": True,
|
||||
"description": "",
|
||||
"end_time": "2023-01-02 00:00:00",
|
||||
"location": "Norge",
|
||||
"message": "Første nyttårsdag",
|
||||
"start_time": "2023-01-01 00:00:00",
|
||||
}
|
||||
|
||||
response = await hass.services.async_call(
|
||||
CALENDAR_DOMAIN,
|
||||
SERVICE_GET_EVENTS,
|
||||
{
|
||||
"entity_id": "calendar.norge",
|
||||
"end_date_time": dt_util.now(),
|
||||
},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert response == {
|
||||
"calendar.norge": {
|
||||
"events": [
|
||||
{
|
||||
"start": "2023-01-01",
|
||||
"end": "2023-01-02",
|
||||
"summary": "Første nyttårsdag",
|
||||
"location": "Norge",
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
# Test with English as exist as optional language for Norway
|
||||
hass.config.language = "en"
|
||||
hass.config.country = "NO"
|
||||
await hass.config_entries.async_reload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
response = await hass.services.async_call(
|
||||
CALENDAR_DOMAIN,
|
||||
SERVICE_GET_EVENTS,
|
||||
{
|
||||
"entity_id": "calendar.norge",
|
||||
"end_date_time": dt_util.now(),
|
||||
},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
)
|
||||
assert response == {
|
||||
"calendar.norge": {
|
||||
"events": [
|
||||
{
|
||||
"start": "2023-01-01",
|
||||
"end": "2023-01-02",
|
||||
"summary": "New Year's Day",
|
||||
"location": "Norge",
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue