mirror of
https://github.com/home-assistant/core.git
synced 2026-12-06 05:38:06 -04:00
Abort NAM zeroconf flow when the device is already configured (#189234)
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user