From 538a1be4d7b019a33e43ebfa44668bd7e5051f8a Mon Sep 17 00:00:00 2001 From: Joe Rivera <2325467+riverajo@users.noreply.github.com> Date: Sun, 11 Oct 2026 22:09:28 -0400 Subject: [PATCH] tplink: Fix new host ignored in reconfigure flow (#182184) --- .../components/tplink/config_flow.py | 2 +- tests/components/tplink/test_config_flow.py | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tplink/config_flow.py b/homeassistant/components/tplink/config_flow.py index cf5f2cc1508b..e7d917c8c7df 100644 --- a/homeassistant/components/tplink/config_flow.py +++ b/homeassistant/components/tplink/config_flow.py @@ -830,7 +830,7 @@ class TPLinkConfigFlow(ConfigFlow, domain=DOMAIN): port = reconfigure_entry.data.get(CONF_PORT) if user_input is not None: - host, port = self._async_get_host_port(host) + host, port = self._async_get_host_port(user_input[CONF_HOST]) self.host = host credentials = await get_credentials(self.hass) diff --git a/tests/components/tplink/test_config_flow.py b/tests/components/tplink/test_config_flow.py index e9ccaff15300..a3ecc3ec2281 100644 --- a/tests/components/tplink/test_config_flow.py +++ b/tests/components/tplink/test_config_flow.py @@ -2324,13 +2324,29 @@ async def test_reauth_update_other_flows( assert len(flows) == 0 +@pytest.mark.parametrize( + "host", + [ + pytest.param(IP_ADDRESS, id="unchanged_host"), + pytest.param("127.0.0.99", id="changed_host"), + ], +) async def test_reconfigure( hass: HomeAssistant, mock_added_config_entry: MockConfigEntry, mock_discovery: AsyncMock, mock_connect: AsyncMock, + host: str, ) -> None: """Test reconfigure flow.""" + device = _mocked_device( + device_config=DeviceConfig.from_dict(DEVICE_CONFIG_KLAP.to_dict()), + credentials_hash=CREDENTIALS_HASH_KLAP, + ip_address=host, + ) + mock_discovery["mock_devices"][host] = device + mock_connect["mock_devices"][host] = device + result = await mock_added_config_entry.start_reconfigure_flow(hass) assert result["type"] is FlowResultType.FORM @@ -2339,12 +2355,14 @@ async def test_reconfigure( result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={ - CONF_HOST: IP_ADDRESS, + CONF_HOST: host, }, ) assert result["type"] is FlowResultType.ABORT assert result["reason"] == "reconfigure_successful" + assert mock_added_config_entry.data[CONF_HOST] == host + await hass.async_block_till_done() async def test_reconfigure_auth_discovered( @@ -2368,7 +2386,7 @@ async def test_reconfigure_auth_discovered( result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={ - CONF_HOST: "WRONG_IP", + CONF_HOST: IP_ADDRESS, }, )