1 """Config flow for Holiday integration."""
3 from __future__
import annotations
7 from babel
import Locale, UnknownLocaleError
8 from holidays
import list_supported_countries
9 import voluptuous
as vol
15 CountrySelectorConfig,
21 from .const
import CONF_PROVINCE, DOMAIN
23 SUPPORTED_COUNTRIES = list_supported_countries(include_aliases=
False)
27 """Handle a config flow for Holiday."""
32 """Initialize the config flow."""
33 self.
datadata: dict[str, Any] = {}
36 self, user_input: dict[str, Any] |
None =
None
37 ) -> ConfigFlowResult:
38 """Handle the initial step."""
39 if user_input
is not None:
42 selected_country = user_input[CONF_COUNTRY]
44 if SUPPORTED_COUNTRIES[selected_country]:
50 locale = Locale.parse(self.hass.config.language, sep=
"-")
51 except UnknownLocaleError:
55 title = locale.territories[selected_country]
58 user_schema = vol.Schema(
61 CONF_COUNTRY, default=self.hass.config.country
64 countries=
list(SUPPORTED_COUNTRIES),
73 self, user_input: dict[str, Any] |
None =
None
74 ) -> ConfigFlowResult:
75 """Handle the province step."""
76 if user_input
is not None:
77 combined_input: dict[str, Any] = {**self.
datadata, **user_input}
79 country = combined_input[CONF_COUNTRY]
80 province = combined_input.get(CONF_PROVINCE)
84 CONF_COUNTRY: country,
85 CONF_PROVINCE: province,
90 locale = Locale.parse(self.hass.config.language, sep=
"-")
91 except UnknownLocaleError:
95 province_str = f
", {province}" if province
else ""
96 name = f
"{locale.territories[country]}{province_str}"
100 province_schema = vol.Schema(
104 options=SUPPORTED_COUNTRIES[self.
datadata[CONF_COUNTRY]],
105 mode=SelectSelectorMode.DROPDOWN,
114 self, user_input: dict[str, Any] |
None =
None
115 ) -> ConfigFlowResult:
116 """Handle the re-configuration of a province."""
118 if user_input
is not None:
119 combined_input: dict[str, Any] = {**reconfigure_entry.data, **user_input}
121 country = combined_input[CONF_COUNTRY]
122 province = combined_input.get(CONF_PROVINCE)
126 CONF_COUNTRY: country,
127 CONF_PROVINCE: province,
132 locale = Locale.parse(self.hass.config.language, sep=
"-")
133 except UnknownLocaleError:
136 locale = Locale(
"en")
137 province_str = f
", {province}" if province
else ""
138 name = f
"{locale.territories[country]}{province_str}"
141 reconfigure_entry, title=name, data=combined_input
144 province_schema = vol.Schema(
148 options=SUPPORTED_COUNTRIES[
149 reconfigure_entry.data[CONF_COUNTRY]
151 mode=SelectSelectorMode.DROPDOWN,
ConfigFlowResult async_step_user(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_province(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_step_reconfigure(self, dict[str, Any]|None user_input=None)
ConfigFlowResult async_create_entry(self, *str title, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None, Mapping[str, Any]|None options=None)
ConfigFlowResult async_update_reload_and_abort(self, ConfigEntry entry, *str|None|UndefinedType unique_id=UNDEFINED, str|UndefinedType title=UNDEFINED, Mapping[str, Any]|UndefinedType data=UNDEFINED, Mapping[str, Any]|UndefinedType data_updates=UNDEFINED, Mapping[str, Any]|UndefinedType options=UNDEFINED, str|UndefinedType reason=UNDEFINED, bool reload_even_if_entry_is_unchanged=True)
None _async_abort_entries_match(self, dict[str, Any]|None match_dict=None)
ConfigEntry _get_reconfigure_entry(self)
ConfigFlowResult async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_show_form(self, *str|None step_id=None, vol.Schema|None data_schema=None, dict[str, str]|None errors=None, Mapping[str, str]|None description_placeholders=None, bool|None last_step=None, str|None preview=None)
_FlowResultT async_create_entry(self, *str|None title=None, Mapping[str, Any] data, str|None description=None, Mapping[str, str]|None description_placeholders=None)