Skip to content

Commit

Permalink
Improve type hints in nina config flow (#124910)
Browse files Browse the repository at this point in the history
* Improve type hints in nina config flow

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <[email protected]>

---------

Co-authored-by: Joost Lekkerkerker <[email protected]>
  • Loading branch information
epenet and joostlek authored Aug 30, 2024
1 parent 74fa30e commit df2ea1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
52 changes: 27 additions & 25 deletions homeassistant/components/nina/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ def __init__(self, config_entry: ConfigEntry) -> None:
if name not in self.data:
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."""
errors: dict[str, Any] = {}
errors: dict[str, str] = {}

if not self._all_region_codes_sorted:
nina: Nina = Nina(async_get_clientsession(self.hass))
Expand Down Expand Up @@ -244,33 +246,33 @@ async def async_step_init(self, user_input=None):
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"

schema: VolDictType = {
**{
vol.Optional(region, default=self.data[region]): cv.multi_select(
self.regions[region]
)
for region in CONST_REGIONS
},
vol.Required(
CONF_MESSAGE_SLOTS,
default=self.data[CONF_MESSAGE_SLOTS],
): vol.All(int, vol.Range(min=1, max=20)),
vol.Optional(
CONF_HEADLINE_FILTER,
default=self.data[CONF_HEADLINE_FILTER],
): cv.string,
vol.Optional(
CONF_AREA_FILTER,
default=self.data[CONF_AREA_FILTER],
): cv.string,
}

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
**{
vol.Optional(
region, default=self.data[region]
): cv.multi_select(self.regions[region])
for region in CONST_REGIONS
},
vol.Required(
CONF_MESSAGE_SLOTS,
default=self.data[CONF_MESSAGE_SLOTS],
): vol.All(int, vol.Range(min=1, max=20)),
vol.Optional(
CONF_HEADLINE_FILTER,
default=self.data[CONF_HEADLINE_FILTER],
): cv.string,
vol.Optional(
CONF_AREA_FILTER,
default=self.data[CONF_AREA_FILTER],
): cv.string,
}
),
data_schema=vol.Schema(schema),
errors=errors,
)
2 changes: 1 addition & 1 deletion tests/components/nina/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
)

assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["data"] is None
assert result["data"] == {}

assert dict(config_entry.data) == {
CONF_HEADLINE_FILTER: deepcopy(DUMMY_DATA[CONF_HEADLINE_FILTER]),
Expand Down

0 comments on commit df2ea1e

Please sign in to comment.