diff --git a/custom_components/holidays/config_flow.py b/custom_components/holidays/config_flow.py index c7a1b67..044c36b 100644 --- a/custom_components/holidays/config_flow.py +++ b/custom_components/holidays/config_flow.py @@ -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" @@ -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))