Update SMA host from DHCP discovery (#183335)

This commit is contained in:
Erwin Douna
2026-09-28 23:46:43 +02:00
committed by GitHub
parent ef8e856c9c
commit 906e125cbd
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -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()
+20
View File
@@ -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,