Skip to content

Commit

Permalink
Cleanup unnecessary reconfigure_confirm in fritz config flow (home-as…
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 11, 2024
1 parent d507581 commit 7097315
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
41 changes: 15 additions & 26 deletions homeassistant/components/fritz/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,7 @@ async def async_step_reauth_confirm(
},
)

async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reconfigure flow ."""
entry_data = self._get_reconfigure_entry().data
self._host = entry_data[CONF_HOST]
self._port = entry_data[CONF_PORT]
self._username = entry_data[CONF_USERNAME]
self._password = entry_data[CONF_PASSWORD]
self._use_tls = entry_data.get(CONF_SSL, DEFAULT_SSL)

return await self.async_step_reconfigure_confirm()

def _show_setup_form_reconfigure_confirm(
def _show_setup_form_reconfigure(
self, user_input: dict[str, Any], errors: dict[str, str] | None = None
) -> ConfigFlowResult:
"""Show the reconfigure form to the user."""
Expand All @@ -358,47 +345,49 @@ def _show_setup_form_reconfigure_confirm(
}

return self.async_show_form(
step_id="reconfigure_confirm",
step_id="reconfigure",
data_schema=vol.Schema(
{
vol.Required(CONF_HOST, default=user_input[CONF_HOST]): str,
**advanced_data_schema,
vol.Required(CONF_SSL, default=user_input[CONF_SSL]): bool,
}
),
description_placeholders={"host": self._host},
description_placeholders={"host": user_input[CONF_HOST]},
errors=errors or {},
)

async def async_step_reconfigure_confirm(
async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reconfigure flow."""
if user_input is None:
return self._show_setup_form_reconfigure_confirm(
reconfigure_entry_data = self._get_reconfigure_entry().data
return self._show_setup_form_reconfigure(
{
CONF_HOST: self._host,
CONF_PORT: self._port,
CONF_SSL: self._use_tls,
CONF_HOST: reconfigure_entry_data[CONF_HOST],
CONF_PORT: reconfigure_entry_data[CONF_PORT],
CONF_SSL: reconfigure_entry_data.get(CONF_SSL, DEFAULT_SSL),
}
)

self._host = user_input[CONF_HOST]
self._use_tls = user_input[CONF_SSL]
self._port = self._determine_port(user_input)

reconfigure_entry = self._get_reconfigure_entry()
self._username = reconfigure_entry.data[CONF_USERNAME]
self._password = reconfigure_entry.data[CONF_PASSWORD]
if error := await self.async_fritz_tools_init():
return self._show_setup_form_reconfigure_confirm(
return self._show_setup_form_reconfigure(
user_input={**user_input, CONF_PORT: self._port}, errors={"base": error}
)

return self.async_update_reload_and_abort(
self._get_reconfigure_entry(),
data={
reconfigure_entry,
data_updates={
CONF_HOST: self._host,
CONF_PASSWORD: self._password,
CONF_PORT: self._port,
CONF_USERNAME: self._username,
CONF_SSL: self._use_tls,
},
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/fritz/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"password": "[%key:common::config_flow::data::password%]"
}
},
"reconfigure_confirm": {
"reconfigure": {
"title": "Updating FRITZ!Box Tools - configuration",
"description": "Update FRITZ!Box Tools configuration for: {host}.",
"data": {
Expand Down
6 changes: 3 additions & 3 deletions tests/components/fritz/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ async def test_reconfigure_successful(
)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["step_id"] == "reconfigure"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand Down Expand Up @@ -512,7 +512,7 @@ async def test_reconfigure_not_successful(
result = await mock_config.start_reconfigure_flow(hass)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["step_id"] == "reconfigure"

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -523,7 +523,7 @@ async def test_reconfigure_not_successful(
)

assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm"
assert result["step_id"] == "reconfigure"
assert result["errors"]["base"] == ERROR_CANNOT_CONNECT

result = await hass.config_entries.flow.async_configure(
Expand Down

0 comments on commit 7097315

Please sign in to comment.