Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type hints in nina config flow #124910

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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={})
Copy link
Contributor Author

@epenet epenet Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to #124861
async_create_entry doesn't allow data None


errors["base"] = "no_selection"

schema: dict[vol.Marker, Any] = {
epenet marked this conversation as resolved.
Show resolved Hide resolved
**{
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
Loading