diff --git a/homeassistant/components/sma/config_flow.py b/homeassistant/components/sma/config_flow.py index 321fb2812e51..8ed6e6938c54 100644 --- a/homeassistant/components/sma/config_flow.py +++ b/homeassistant/components/sma/config_flow.py @@ -298,7 +298,7 @@ class SmaConfigFlow(ConfigFlow, domain=DOMAIN): if not (match := HOSTNAME_SERIAL.match(discovery_info.hostname)): return self.async_abort(reason="not_supported") await self.async_set_unique_id(match.group(1)) - self._abort_if_unique_id_configured() + self._abort_if_unique_id_configured(updates={CONF_HOST: self._data[CONF_HOST]}) return await self.async_step_discovery_confirm() diff --git a/tests/components/sma/test_config_flow.py b/tests/components/sma/test_config_flow.py index 2d362da92843..725e53705c9e 100644 --- a/tests/components/sma/test_config_flow.py +++ b/tests/components/sma/test_config_flow.py @@ -195,6 +195,26 @@ async def test_dhcp_already_configured( assert result["reason"] == "already_configured" +@pytest.mark.usefixtures("mock_setup_entry") +async def test_dhcp_updates_host( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Test DHCP discovery updates the host of a device that changed IP address.""" + mock_config_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_DHCP}, + data=DhcpServiceInfo( + ip="1.1.1.2", hostname="SMA123456789", macaddress="0015bb00abcd" + ), + ) + + assert result["type"] is FlowResultType.ABORT + assert result["reason"] == "already_configured" + assert mock_config_entry.data[CONF_HOST] == "1.1.1.2" + + async def test_dhcp_already_configured_duplicate( hass: HomeAssistant, mock_config_entry: MockConfigEntry,