From 0b932b53c9299b6b09206a7239dd936e423e103c Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sun, 17 Oct 2021 12:12:01 +0200 Subject: [PATCH] Do not probe `nam` device if the host is already configured (#57843) --- homeassistant/components/nam/config_flow.py | 3 +++ tests/components/nam/test_config_flow.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/homeassistant/components/nam/config_flow.py b/homeassistant/components/nam/config_flow.py index a44f3f2ba6a..458895e69c5 100644 --- a/homeassistant/components/nam/config_flow.py +++ b/homeassistant/components/nam/config_flow.py @@ -74,6 +74,9 @@ class NAMFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): """Handle zeroconf discovery.""" self.host = discovery_info[CONF_HOST] + # Do not probe the device if the host is already configured + self._async_abort_entries_match({CONF_HOST: self.host}) + try: mac = await self._async_get_mac(cast(str, self.host)) except (ApiError, ClientConnectorError, asyncio.TimeoutError): diff --git a/tests/components/nam/test_config_flow.py b/tests/components/nam/test_config_flow.py index 99a252ada0a..b0ecb20da11 100644 --- a/tests/components/nam/test_config_flow.py +++ b/tests/components/nam/test_config_flow.py @@ -150,6 +150,23 @@ async def test_zeroconf(hass): assert len(mock_setup_entry.mock_calls) == 1 +async def test_zeroconf_host_already_configured(hass): + """Test that errors are shown when host is already configured.""" + entry = MockConfigEntry( + domain=DOMAIN, unique_id="aa:bb:cc:dd:ee:ff", data=VALID_CONFIG + ) + entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, + data=DISCOVERY_INFO, + context={"source": SOURCE_ZEROCONF}, + ) + + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == "already_configured" + + @pytest.mark.parametrize( "error", [