Improve type hints in nina config flow (#124910)

* Improve type hints in nina config flow

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
epenet 2024-08-30 11:21:05 +02:00 committed by GitHub
parent 74fa30e59d
commit df2ea1e875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 26 deletions

View File

@ -182,9 +182,11 @@ class OptionsFlowHandler(OptionsFlow):
if name not in self.data: if name not in self.data:
self.data[name] = [] self.data[name] = []
async def async_step_init(self, user_input=None): async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle options flow.""" """Handle options flow."""
errors: dict[str, Any] = {} errors: dict[str, str] = {}
if not self._all_region_codes_sorted: if not self._all_region_codes_sorted:
nina: Nina = Nina(async_get_clientsession(self.hass)) nina: Nina = Nina(async_get_clientsession(self.hass))
@ -244,18 +246,15 @@ class OptionsFlowHandler(OptionsFlow):
self.config_entry, data=user_input self.config_entry, data=user_input
) )
return self.async_create_entry(title="", data=None) return self.async_create_entry(title="", data={})
errors["base"] = "no_selection" errors["base"] = "no_selection"
return self.async_show_form( schema: VolDictType = {
step_id="init",
data_schema=vol.Schema(
{
**{ **{
vol.Optional( vol.Optional(region, default=self.data[region]): cv.multi_select(
region, default=self.data[region] self.regions[region]
): cv.multi_select(self.regions[region]) )
for region in CONST_REGIONS for region in CONST_REGIONS
}, },
vol.Required( vol.Required(
@ -271,6 +270,9 @@ class OptionsFlowHandler(OptionsFlow):
default=self.data[CONF_AREA_FILTER], default=self.data[CONF_AREA_FILTER],
): cv.string, ): cv.string,
} }
),
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(schema),
errors=errors, errors=errors,
) )

View File

@ -188,7 +188,7 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
) )
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] is None assert result["data"] == {}
assert dict(config_entry.data) == { assert dict(config_entry.data) == {
CONF_HEADLINE_FILTER: deepcopy(DUMMY_DATA[CONF_HEADLINE_FILTER]), CONF_HEADLINE_FILTER: deepcopy(DUMMY_DATA[CONF_HEADLINE_FILTER]),