Cleanup unnecessary reconfigure_confirm in fritzbox config flow (#128087)

This commit is contained in:
epenet 2024-10-12 08:42:59 +02:00 committed by GitHub
parent 8e9e738bb8
commit abe02c3843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 25 deletions

View file

@ -220,18 +220,6 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN):
async def async_step_reconfigure( async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user."""
entry_data = self._get_reconfigure_entry().data
self._name = entry_data[CONF_HOST]
self._host = entry_data[CONF_HOST]
self._username = entry_data[CONF_USERNAME]
self._password = entry_data[CONF_PASSWORD]
return await self.async_step_reconfigure_confirm()
async def async_step_reconfigure_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Handle a reconfiguration flow initialized by the user.""" """Handle a reconfiguration flow initialized by the user."""
errors = {} errors = {}
@ -239,26 +227,27 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
self._host = user_input[CONF_HOST] self._host = user_input[CONF_HOST]
reconfigure_entry = self._get_reconfigure_entry()
self._username = reconfigure_entry.data[CONF_USERNAME]
self._password = reconfigure_entry.data[CONF_PASSWORD]
result = await self.async_try_connect() result = await self.async_try_connect()
if result == RESULT_SUCCESS: if result == RESULT_SUCCESS:
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(
self._get_reconfigure_entry(), reconfigure_entry,
data={ data_updates={CONF_HOST: self._host},
CONF_HOST: self._host,
CONF_PASSWORD: self._password,
CONF_USERNAME: self._username,
},
) )
errors["base"] = result errors["base"] = result
host = self._get_reconfigure_entry().data[CONF_HOST]
return self.async_show_form( return self.async_show_form(
step_id="reconfigure_confirm", step_id="reconfigure",
data_schema=vol.Schema( data_schema=vol.Schema(
{ {
vol.Required(CONF_HOST, default=self._host): str, vol.Required(CONF_HOST, default=host): str,
} }
), ),
description_placeholders={"name": self._name}, description_placeholders={"name": host},
errors=errors, errors=errors,
) )

View file

@ -27,7 +27,7 @@
"password": "[%key:common::config_flow::data::password%]" "password": "[%key:common::config_flow::data::password%]"
} }
}, },
"reconfigure_confirm": { "reconfigure": {
"description": "Update your configuration information for {name}.", "description": "Update your configuration information for {name}.",
"data": { "data": {
"host": "[%key:common::config_flow::data::host%]" "host": "[%key:common::config_flow::data::host%]"

View file

@ -198,7 +198,7 @@ async def test_reconfigure_success(hass: HomeAssistant, fritz: Mock) -> None:
result = await mock_config.start_reconfigure_flow(hass) result = await mock_config.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -227,7 +227,7 @@ async def test_reconfigure_failed(hass: HomeAssistant, fritz: Mock) -> None:
result = await mock_config.start_reconfigure_flow(hass) result = await mock_config.start_reconfigure_flow(hass)
assert result["type"] is FlowResultType.FORM 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 = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -236,7 +236,7 @@ async def test_reconfigure_failed(hass: HomeAssistant, fritz: Mock) -> None:
}, },
) )
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure_confirm" assert result["step_id"] == "reconfigure"
assert result["errors"]["base"] == "no_devices_found" assert result["errors"]["base"] == "no_devices_found"
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(