From 8e71086c2177f988282c35b2009f3e7902538d60 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Mon, 13 Nov 2023 13:41:46 +0100 Subject: [PATCH] Workday add languages (#103127) --- homeassistant/components/workday/__init__.py | 10 ++- .../components/workday/binary_sensor.py | 6 +- .../components/workday/config_flow.py | 53 +++++++---- homeassistant/components/workday/strings.json | 12 ++- tests/components/workday/__init__.py | 30 +++++++ .../components/workday/test_binary_sensor.py | 2 + tests/components/workday/test_config_flow.py | 90 ++++++++++++++++++- 7 files changed, 177 insertions(+), 26 deletions(-) diff --git a/homeassistant/components/workday/__init__.py b/homeassistant/components/workday/__init__.py index 558e0aa9ecf..455f5d4618a 100644 --- a/homeassistant/components/workday/__init__.py +++ b/homeassistant/components/workday/__init__.py @@ -1,9 +1,10 @@ """Sensor to indicate whether the current day is a workday.""" from __future__ import annotations -from holidays import list_supported_countries +from holidays import HolidayBase, country_holidays, list_supported_countries from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_LANGUAGE from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryError from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue @@ -17,6 +18,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: country: str | None = entry.options.get(CONF_COUNTRY) province: str | None = entry.options.get(CONF_PROVINCE) + if country and CONF_LANGUAGE not in entry.options: + cls: HolidayBase = country_holidays(country, subdiv=province) + default_language = cls.default_language + new_options = entry.options.copy() + new_options[CONF_LANGUAGE] = default_language + hass.config_entries.async_update_entry(entry, options=new_options) + if country and country not in list_supported_countries(): async_create_issue( hass, diff --git a/homeassistant/components/workday/binary_sensor.py b/homeassistant/components/workday/binary_sensor.py index 2692c27d58a..26f44fa1e2d 100644 --- a/homeassistant/components/workday/binary_sensor.py +++ b/homeassistant/components/workday/binary_sensor.py @@ -13,7 +13,7 @@ import voluptuous as vol from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_NAME +from homeassistant.const import CONF_LANGUAGE, CONF_NAME from homeassistant.core import HomeAssistant, ServiceResponse, SupportsResponse import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo @@ -72,16 +72,16 @@ async def async_setup_entry( province: str | None = entry.options.get(CONF_PROVINCE) sensor_name: str = entry.options[CONF_NAME] workdays: list[str] = entry.options[CONF_WORKDAYS] + language: str | None = entry.options.get(CONF_LANGUAGE) year: int = (dt_util.now() + timedelta(days=days_offset)).year if country: - cls: HolidayBase = country_holidays(country, subdiv=province, years=year) obj_holidays: HolidayBase = country_holidays( country, subdiv=province, years=year, - language=cls.default_language, + language=language, ) else: obj_holidays = HolidayBase() diff --git a/homeassistant/components/workday/config_flow.py b/homeassistant/components/workday/config_flow.py index c4b1f1ba3fd..1fbeea0684d 100644 --- a/homeassistant/components/workday/config_flow.py +++ b/homeassistant/components/workday/config_flow.py @@ -11,7 +11,7 @@ from homeassistant.config_entries import ( ConfigFlow, OptionsFlowWithConfigEntry, ) -from homeassistant.const import CONF_NAME +from homeassistant.const import CONF_LANGUAGE, CONF_NAME from homeassistant.core import callback from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.exceptions import HomeAssistantError @@ -46,7 +46,7 @@ from .const import ( ) -def add_province_to_schema( +def add_province_and_language_to_schema( schema: vol.Schema, country: str | None, ) -> vol.Schema: @@ -55,20 +55,36 @@ def add_province_to_schema( return schema all_countries = list_supported_countries(include_aliases=False) - if not all_countries.get(country): - return schema - add_schema = { - vol.Optional(CONF_PROVINCE): SelectSelector( - SelectSelectorConfig( - options=all_countries[country], - mode=SelectSelectorMode.DROPDOWN, - translation_key=CONF_PROVINCE, + language_schema = {} + province_schema = {} + + _country = country_holidays(country=country) + if country_default_language := (_country.default_language): + selectable_languages = _country.supported_languages + language_schema = { + vol.Optional( + CONF_LANGUAGE, default=country_default_language + ): SelectSelector( + SelectSelectorConfig( + options=list(selectable_languages), + mode=SelectSelectorMode.DROPDOWN, + ) ) - ), - } + } - return vol.Schema({**DATA_SCHEMA_OPT.schema, **add_schema}) + if provinces := all_countries.get(country): + province_schema = { + vol.Optional(CONF_PROVINCE): SelectSelector( + SelectSelectorConfig( + options=provinces, + mode=SelectSelectorMode.DROPDOWN, + translation_key=CONF_PROVINCE, + ) + ), + } + + return vol.Schema({**DATA_SCHEMA_OPT.schema, **language_schema, **province_schema}) def _is_valid_date_range(check_date: str, error: type[HomeAssistantError]) -> bool: @@ -93,12 +109,11 @@ def validate_custom_dates(user_input: dict[str, Any]) -> None: year: int = dt_util.now().year if country := user_input.get(CONF_COUNTRY): - cls = country_holidays(country) obj_holidays = country_holidays( country=country, subdiv=user_input.get(CONF_PROVINCE), years=year, - language=cls.default_language, + language=user_input.get(CONF_LANGUAGE), ) else: obj_holidays = HolidayBase(years=year) @@ -237,7 +252,9 @@ class WorkdayConfigFlow(ConfigFlow, domain=DOMAIN): ) schema = await self.hass.async_add_executor_job( - add_province_to_schema, DATA_SCHEMA_OPT, self.data.get(CONF_COUNTRY) + add_province_and_language_to_schema, + DATA_SCHEMA_OPT, + self.data.get(CONF_COUNTRY), ) new_schema = self.add_suggested_values_to_schema(schema, user_input) return self.async_show_form( @@ -298,7 +315,9 @@ class WorkdayOptionsFlowHandler(OptionsFlowWithConfigEntry): return self.async_create_entry(data=combined_input) schema: vol.Schema = await self.hass.async_add_executor_job( - add_province_to_schema, DATA_SCHEMA_OPT, self.options.get(CONF_COUNTRY) + add_province_and_language_to_schema, + DATA_SCHEMA_OPT, + self.options.get(CONF_COUNTRY), ) new_schema = self.add_suggested_values_to_schema( diff --git a/homeassistant/components/workday/strings.json b/homeassistant/components/workday/strings.json index a05ab1fc669..20e7cd26fd6 100644 --- a/homeassistant/components/workday/strings.json +++ b/homeassistant/components/workday/strings.json @@ -19,7 +19,8 @@ "workdays": "Workdays", "add_holidays": "Add holidays", "remove_holidays": "Remove Holidays", - "province": "Subdivision of country" + "province": "Subdivision of country", + "language": "Language for named holidays" }, "data_description": { "excludes": "List of workdays to exclude", @@ -27,7 +28,8 @@ "workdays": "List of workdays", "add_holidays": "Add custom holidays as YYYY-MM-DD or as range using `,` as separator", "remove_holidays": "Remove holidays as YYYY-MM-DD, as range using `,` as separator or by using partial of name", - "province": "State, Territory, Province, Region of Country" + "province": "State, Territory, Province, Region of Country", + "language": "Choose the language you want to configure named holidays after" } } }, @@ -48,7 +50,8 @@ "workdays": "[%key:component::workday::config::step::options::data::workdays%]", "add_holidays": "[%key:component::workday::config::step::options::data::add_holidays%]", "remove_holidays": "[%key:component::workday::config::step::options::data::remove_holidays%]", - "province": "[%key:component::workday::config::step::options::data::province%]" + "province": "[%key:component::workday::config::step::options::data::province%]", + "language": "[%key:component::workday::config::step::options::data::language%]" }, "data_description": { "excludes": "[%key:component::workday::config::step::options::data_description::excludes%]", @@ -56,7 +59,8 @@ "workdays": "[%key:component::workday::config::step::options::data_description::workdays%]", "add_holidays": "[%key:component::workday::config::step::options::data_description::add_holidays%]", "remove_holidays": "[%key:component::workday::config::step::options::data_description::remove_holidays%]", - "province": "[%key:component::workday::config::step::options::data_description::province%]" + "province": "[%key:component::workday::config::step::options::data_description::province%]", + "language": "[%key:component::workday::config::step::options::data_description::language%]" } } }, diff --git a/tests/components/workday/__init__.py b/tests/components/workday/__init__.py index f9e44359b00..f2744758efb 100644 --- a/tests/components/workday/__init__.py +++ b/tests/components/workday/__init__.py @@ -65,6 +65,17 @@ TEST_CONFIG_WITH_PROVINCE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", +} +TEST_CONFIG_NO_LANGUAGE_CONFIGURED = { + "name": DEFAULT_NAME, + "country": "DE", + "province": "BW", + "excludes": DEFAULT_EXCLUDES, + "days_offset": DEFAULT_OFFSET, + "workdays": DEFAULT_WORKDAYS, + "add_holidays": [], + "remove_holidays": [], } TEST_CONFIG_INCORRECT_COUNTRY = { "name": DEFAULT_NAME, @@ -74,6 +85,7 @@ TEST_CONFIG_INCORRECT_COUNTRY = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_INCORRECT_PROVINCE = { "name": DEFAULT_NAME, @@ -84,6 +96,7 @@ TEST_CONFIG_INCORRECT_PROVINCE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_NO_PROVINCE = { "name": DEFAULT_NAME, @@ -93,6 +106,7 @@ TEST_CONFIG_NO_PROVINCE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_WITH_STATE = { "name": DEFAULT_NAME, @@ -103,6 +117,7 @@ TEST_CONFIG_WITH_STATE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "en_US", } TEST_CONFIG_NO_STATE = { "name": DEFAULT_NAME, @@ -112,6 +127,7 @@ TEST_CONFIG_NO_STATE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "en_US", } TEST_CONFIG_INCLUDE_HOLIDAY = { "name": DEFAULT_NAME, @@ -122,6 +138,7 @@ TEST_CONFIG_INCLUDE_HOLIDAY = { "workdays": ["holiday"], "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_EXAMPLE_1 = { "name": DEFAULT_NAME, @@ -131,6 +148,7 @@ TEST_CONFIG_EXAMPLE_1 = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "en_US", } TEST_CONFIG_EXAMPLE_2 = { "name": DEFAULT_NAME, @@ -141,6 +159,7 @@ TEST_CONFIG_EXAMPLE_2 = { "workdays": ["mon", "wed", "fri"], "add_holidays": ["2020-02-24"], "remove_holidays": [], + "language": "de", } TEST_CONFIG_REMOVE_HOLIDAY = { "name": DEFAULT_NAME, @@ -150,6 +169,7 @@ TEST_CONFIG_REMOVE_HOLIDAY = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": ["2020-12-25", "2020-11-26"], + "language": "en_US", } TEST_CONFIG_REMOVE_NAMED = { "name": DEFAULT_NAME, @@ -159,6 +179,7 @@ TEST_CONFIG_REMOVE_NAMED = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": ["Not a Holiday", "Christmas", "Thanksgiving"], + "language": "en_US", } TEST_CONFIG_TOMORROW = { "name": DEFAULT_NAME, @@ -168,6 +189,7 @@ TEST_CONFIG_TOMORROW = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_DAY_AFTER_TOMORROW = { "name": DEFAULT_NAME, @@ -177,6 +199,7 @@ TEST_CONFIG_DAY_AFTER_TOMORROW = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_YESTERDAY = { "name": DEFAULT_NAME, @@ -186,6 +209,7 @@ TEST_CONFIG_YESTERDAY = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": [], + "language": "de", } TEST_CONFIG_INCORRECT_ADD_REMOVE = { "name": DEFAULT_NAME, @@ -196,6 +220,7 @@ TEST_CONFIG_INCORRECT_ADD_REMOVE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": ["2023-12-32"], "remove_holidays": ["2023-12-32"], + "language": "de", } TEST_CONFIG_INCORRECT_ADD_DATE_RANGE = { "name": DEFAULT_NAME, @@ -206,6 +231,7 @@ TEST_CONFIG_INCORRECT_ADD_DATE_RANGE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": ["2023-12-01", "2023-12-30,2023-12-32"], "remove_holidays": [], + "language": "de", } TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE = { "name": DEFAULT_NAME, @@ -216,6 +242,7 @@ TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": ["2023-12-25", "2023-12-30,2023-12-32"], + "language": "de", } TEST_CONFIG_INCORRECT_ADD_DATE_RANGE_LEN = { "name": DEFAULT_NAME, @@ -226,6 +253,7 @@ TEST_CONFIG_INCORRECT_ADD_DATE_RANGE_LEN = { "workdays": DEFAULT_WORKDAYS, "add_holidays": ["2023-12-01", "2023-12-29,2023-12-30,2023-12-31"], "remove_holidays": [], + "language": "de", } TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE_LEN = { "name": DEFAULT_NAME, @@ -236,6 +264,7 @@ TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE_LEN = { "workdays": DEFAULT_WORKDAYS, "add_holidays": [], "remove_holidays": ["2023-12-25", "2023-12-29,2023-12-30,2023-12-31"], + "language": "de", } TEST_CONFIG_ADD_REMOVE_DATE_RANGE = { "name": DEFAULT_NAME, @@ -246,4 +275,5 @@ TEST_CONFIG_ADD_REMOVE_DATE_RANGE = { "workdays": DEFAULT_WORKDAYS, "add_holidays": ["2022-12-01", "2022-12-05,2022-12-15"], "remove_holidays": ["2022-12-04", "2022-12-24,2022-12-26"], + "language": "de", } diff --git a/tests/components/workday/test_binary_sensor.py b/tests/components/workday/test_binary_sensor.py index e955bd0de0d..6ce5b08ef27 100644 --- a/tests/components/workday/test_binary_sensor.py +++ b/tests/components/workday/test_binary_sensor.py @@ -26,6 +26,7 @@ from . import ( TEST_CONFIG_INCORRECT_REMOVE_DATE_RANGE_LEN, TEST_CONFIG_NO_COUNTRY, TEST_CONFIG_NO_COUNTRY_ADD_HOLIDAY, + TEST_CONFIG_NO_LANGUAGE_CONFIGURED, TEST_CONFIG_NO_PROVINCE, TEST_CONFIG_NO_STATE, TEST_CONFIG_REMOVE_HOLIDAY, @@ -51,6 +52,7 @@ from . import ( (TEST_CONFIG_TOMORROW, "off"), (TEST_CONFIG_DAY_AFTER_TOMORROW, "off"), (TEST_CONFIG_YESTERDAY, "on"), + (TEST_CONFIG_NO_LANGUAGE_CONFIGURED, "off"), ], ) async def test_setup( diff --git a/tests/components/workday/test_config_flow.py b/tests/components/workday/test_config_flow.py index 89a001e0b55..3ecd518ce98 100644 --- a/tests/components/workday/test_config_flow.py +++ b/tests/components/workday/test_config_flow.py @@ -1,6 +1,9 @@ """Test the Workday config flow.""" from __future__ import annotations +from datetime import datetime + +from freezegun.api import FrozenDateTimeFactory import pytest from homeassistant import config_entries @@ -16,9 +19,10 @@ from homeassistant.components.workday.const import ( DEFAULT_WORKDAYS, DOMAIN, ) -from homeassistant.const import CONF_NAME +from homeassistant.const import CONF_LANGUAGE, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from homeassistant.util.dt import UTC from . import init_integration @@ -49,6 +53,7 @@ async def test_form(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: [], CONF_REMOVE_HOLIDAYS: [], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -63,6 +68,7 @@ async def test_form(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": [], "remove_holidays": [], + "language": "de", } @@ -143,6 +149,7 @@ async def test_form_no_subdivision(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": [], "remove_holidays": [], + "language": "sv", } @@ -159,6 +166,7 @@ async def test_options_form(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": [], "remove_holidays": [], + "language": "de", }, ) @@ -173,6 +181,7 @@ async def test_options_form(hass: HomeAssistant) -> None: "add_holidays": [], "remove_holidays": [], "province": "BW", + "language": "de", }, ) @@ -186,6 +195,7 @@ async def test_options_form(hass: HomeAssistant) -> None: "add_holidays": [], "remove_holidays": [], "province": "BW", + "language": "de", } @@ -213,6 +223,7 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-xx-12"], CONF_REMOVE_HOLIDAYS: [], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -226,6 +237,7 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-12-12"], CONF_REMOVE_HOLIDAYS: ["Does not exist"], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -240,6 +252,7 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-12-12"], CONF_REMOVE_HOLIDAYS: ["Weihnachtstag"], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -254,6 +267,7 @@ async def test_form_incorrect_dates(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": ["2022-12-12"], "remove_holidays": ["Weihnachtstag"], + "language": "de", } @@ -270,6 +284,7 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": [], "remove_holidays": [], + "language": "de", }, ) @@ -284,6 +299,7 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None: "add_holidays": ["2022-xx-12"], "remove_holidays": [], "province": "BW", + "language": "de", }, ) @@ -298,6 +314,7 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-12"], "remove_holidays": ["Does not exist"], "province": "BW", + "language": "de", }, ) @@ -312,6 +329,7 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-12"], "remove_holidays": ["Weihnachtstag"], "province": "BW", + "language": "de", }, ) @@ -325,6 +343,7 @@ async def test_options_form_incorrect_dates(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-12"], "remove_holidays": ["Weihnachtstag"], "province": "BW", + "language": "de", } @@ -401,6 +420,7 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-12-12", "2022-12-30,2022-12-32"], CONF_REMOVE_HOLIDAYS: [], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -414,6 +434,7 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-12-12"], CONF_REMOVE_HOLIDAYS: ["2022-12-25", "2022-12-30,2022-12-32"], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -428,6 +449,7 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None: CONF_WORKDAYS: DEFAULT_WORKDAYS, CONF_ADD_HOLIDAYS: ["2022-12-12", "2022-12-01,2022-12-10"], CONF_REMOVE_HOLIDAYS: ["2022-12-25", "2022-12-30,2022-12-31"], + CONF_LANGUAGE: "de", }, ) await hass.async_block_till_done() @@ -442,6 +464,7 @@ async def test_form_incorrect_date_range(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": ["2022-12-12", "2022-12-01,2022-12-10"], "remove_holidays": ["2022-12-25", "2022-12-30,2022-12-31"], + "language": "de", } @@ -458,6 +481,7 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None: "workdays": ["mon", "tue", "wed", "thu", "fri"], "add_holidays": [], "remove_holidays": [], + "language": "de", }, ) @@ -472,6 +496,7 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-30,2022-12-32"], "remove_holidays": [], "province": "BW", + "language": "de", }, ) @@ -486,6 +511,7 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-30,2022-12-31"], "remove_holidays": ["2022-13-25,2022-12-26"], "province": "BW", + "language": "de", }, ) @@ -500,6 +526,7 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-30,2022-12-31"], "remove_holidays": ["2022-12-25,2022-12-26"], "province": "BW", + "language": "de", }, ) @@ -513,4 +540,65 @@ async def test_options_form_incorrect_date_ranges(hass: HomeAssistant) -> None: "add_holidays": ["2022-12-30,2022-12-31"], "remove_holidays": ["2022-12-25,2022-12-26"], "province": "BW", + "language": "de", } + + +pytestmark = pytest.mark.usefixtures() + + +@pytest.mark.parametrize( + ("language", "holiday"), + [ + ("de", "Weihnachtstag"), + ("en_US", "Christmas"), + ], +) +async def test_language( + hass: HomeAssistant, language: str, holiday: str, freezer: FrozenDateTimeFactory +) -> None: + """Test we get the forms.""" + freezer.move_to(datetime(2023, 12, 25, 12, tzinfo=UTC)) # Monday + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + assert result["type"] == FlowResultType.FORM + + result2 = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_NAME: "Workday Sensor", + CONF_COUNTRY: "DE", + }, + ) + await hass.async_block_till_done() + result3 = await hass.config_entries.flow.async_configure( + result2["flow_id"], + { + CONF_EXCLUDES: DEFAULT_EXCLUDES, + CONF_OFFSET: DEFAULT_OFFSET, + CONF_WORKDAYS: DEFAULT_WORKDAYS, + CONF_ADD_HOLIDAYS: [], + CONF_REMOVE_HOLIDAYS: [holiday], + CONF_LANGUAGE: language, + }, + ) + await hass.async_block_till_done() + + assert result3["type"] == FlowResultType.CREATE_ENTRY + assert result3["title"] == "Workday Sensor" + assert result3["options"] == { + "name": "Workday Sensor", + "country": "DE", + "excludes": ["sat", "sun", "holiday"], + "days_offset": 0, + "workdays": ["mon", "tue", "wed", "thu", "fri"], + "add_holidays": [], + "remove_holidays": [holiday], + "language": language, + } + + state = hass.states.get("binary_sensor.workday_sensor") + assert state is not None + assert state.state == "on"