Skip to content

Commit

Permalink
configuration for different lang/subdiv combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
bruxy70 committed Nov 6, 2023
1 parent 70a83f0 commit f6c5755
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions custom_components/holidays/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@
@callback
async def choose_second_step(options: Dict[str, Any]) -> str:
"""Return next step_id for options flow."""
subdivs = supported_countries[options.get(const.CONF_COUNTRY)]
languages = localised_countries.get(options.get(const.CONF_COUNTRY), "")
if subdivs or languages != "":
country = options.get(const.CONF_COUNTRY)
subdivs = supported_countries[country]
languages = localised_countries.get(country, "")
if subdivs or languages:
# If country was changed, remove subdivs for the wrong country
if const.CONF_SUBDIV in options and options[const.CONF_SUBDIV] not in subdivs:
if const.CONF_SUBDIV in options and (
not subdivs or options[const.CONF_SUBDIV] not in subdivs
):
del options[const.CONF_SUBDIV]
if (
const.CONF_LANGUAGES in options
and options[const.CONF_LANGUAGES] not in languages
if const.CONF_LANGUAGES in options and (
not languages or options[const.CONF_LANGUAGES] not in languages
):
del options[const.CONF_LANGUAGES]
return "subdiv"
Expand Down Expand Up @@ -145,20 +147,21 @@ async def subdiv_config_schema(
handler: SchemaConfigFlowHandler | SchemaOptionsFlowHandler,
) -> vol.Schema:
"""Second step."""
subdivs = [
selector.SelectOptionDict(value=s, label=s)
for s in supported_countries[handler.options.get(const.CONF_COUNTRY)]
]
languages = [
selector.SelectOptionDict(value=s, label=s)
for s in localised_countries[handler.options.get(const.CONF_COUNTRY)]
]
country = handler.options.get(const.CONF_COUNTRY)
options = {}
if subdivs:
if country in supported_countries:
subdivs = [
selector.SelectOptionDict(value=s, label=s)
for s in supported_countries[handler.options.get(const.CONF_COUNTRY)]
]
options[optional(const.CONF_SUBDIV, handler.options)] = selector.SelectSelector(
selector.SelectSelectorConfig(options=subdivs)
)
if languages:
if country in localised_countries:
languages = [
selector.SelectOptionDict(value=s, label=s)
for s in localised_countries[handler.options.get(const.CONF_COUNTRY)]
]
options[
optional(const.CONF_LANGUAGES, handler.options)
] = selector.SelectSelector(selector.SelectSelectorConfig(options=languages))
Expand Down

0 comments on commit f6c5755

Please sign in to comment.