From abe02c3843e2e7a0ce1675fd6a82742b649595aa Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sat, 12 Oct 2024 08:42:59 +0200 Subject: [PATCH] Cleanup unnecessary reconfigure_confirm in fritzbox config flow (#128087) --- .../components/fritzbox/config_flow.py | 31 ++++++------------- .../components/fritzbox/strings.json | 2 +- tests/components/fritzbox/test_config_flow.py | 6 ++-- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/homeassistant/components/fritzbox/config_flow.py b/homeassistant/components/fritzbox/config_flow.py index 502336533c1..76754fc5082 100644 --- a/homeassistant/components/fritzbox/config_flow.py +++ b/homeassistant/components/fritzbox/config_flow.py @@ -220,18 +220,6 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN): async def async_step_reconfigure( 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: """Handle a reconfiguration flow initialized by the user.""" errors = {} @@ -239,26 +227,27 @@ class FritzboxConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: 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() if result == RESULT_SUCCESS: return self.async_update_reload_and_abort( - self._get_reconfigure_entry(), - data={ - CONF_HOST: self._host, - CONF_PASSWORD: self._password, - CONF_USERNAME: self._username, - }, + reconfigure_entry, + data_updates={CONF_HOST: self._host}, ) errors["base"] = result + host = self._get_reconfigure_entry().data[CONF_HOST] return self.async_show_form( - step_id="reconfigure_confirm", + step_id="reconfigure", 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, ) diff --git a/homeassistant/components/fritzbox/strings.json b/homeassistant/components/fritzbox/strings.json index 2b7dbff0a20..c7c2439b566 100644 --- a/homeassistant/components/fritzbox/strings.json +++ b/homeassistant/components/fritzbox/strings.json @@ -27,7 +27,7 @@ "password": "[%key:common::config_flow::data::password%]" } }, - "reconfigure_confirm": { + "reconfigure": { "description": "Update your configuration information for {name}.", "data": { "host": "[%key:common::config_flow::data::host%]" diff --git a/tests/components/fritzbox/test_config_flow.py b/tests/components/fritzbox/test_config_flow.py index fc63684e5d1..0df6d0b2ea9 100644 --- a/tests/components/fritzbox/test_config_flow.py +++ b/tests/components/fritzbox/test_config_flow.py @@ -198,7 +198,7 @@ async def test_reconfigure_success(hass: HomeAssistant, fritz: Mock) -> None: 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"], @@ -227,7 +227,7 @@ async def test_reconfigure_failed(hass: HomeAssistant, fritz: Mock) -> None: 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"], @@ -236,7 +236,7 @@ async def test_reconfigure_failed(hass: HomeAssistant, fritz: Mock) -> None: }, ) assert result["type"] is FlowResultType.FORM - assert result["step_id"] == "reconfigure_confirm" + assert result["step_id"] == "reconfigure" assert result["errors"]["base"] == "no_devices_found" result = await hass.config_entries.flow.async_configure(