mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
74fa30e59d
commit
df2ea1e875
@ -182,9 +182,11 @@ class OptionsFlowHandler(OptionsFlow):
|
||||
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))
|
||||
@ -244,33 +246,33 @@ class OptionsFlowHandler(OptionsFlow):
|
||||
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,
|
||||
)
|
||||
|
@ -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]),
|
||||
|
Loading…
x
Reference in New Issue
Block a user