Abort NAM zeroconf flow when the device is already configured (#189234)

This commit is contained in:
Maciej Bieniek
2026-10-28 15:37:22 +02:00
committed by GitHub
parent 09a94d1201
commit 0e75ec4467
2 changed files with 31 additions and 0 deletions
@@ -138,6 +138,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
return await self.async_step_confirm_discovery()
await self.async_set_unique_id(format_mac(nam.mac))
self._abort_if_unique_id_configured({CONF_HOST: self.host})
return await self.async_step_confirm_discovery()
+30
View File
@@ -395,6 +395,36 @@ async def test_zeroconf_host_already_configured(hass: HomeAssistant) -> None:
assert result["reason"] == "already_configured"
async def test_zeroconf_already_configured_host_changed(hass: HomeAssistant) -> None:
"""Test that the host is updated when a configured device is discovered with a new IP."""
entry = MockConfigEntry(
domain=DOMAIN, unique_id="aa:bb:cc:dd:ee:ff", data=VALID_CONFIG
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
data=ZeroconfServiceInfo(
ip_address=ip_address("10.10.2.99"),
ip_addresses=[ip_address("10.10.2.99")],
hostname="mock_hostname",
name="mock_name",
port=None,
properties={},
type="mock_type",
),
context={"source": SOURCE_ZEROCONF},
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.data[CONF_HOST] == "10.10.2.99"
@pytest.mark.parametrize(
"error",
[