From c9cc024e9b8f6ba464a24fc03869abff98dc30c3 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Thu, 16 Apr 2020 19:16:35 -0400 Subject: [PATCH] Abort vizio zeroconf config flow if unique ID is already configured (#34313) --- homeassistant/components/vizio/config_flow.py | 1 + tests/components/vizio/const.py | 1 + tests/components/vizio/test_config_flow.py | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index eac6df85f437..379f6c48ace0 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -341,6 +341,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): await self.async_set_unique_id( unique_id=discovery_info[CONF_HOST].split(":")[0], raise_on_progress=True ) + self._abort_if_unique_id_configured() discovery_info[ CONF_HOST diff --git a/tests/components/vizio/const.py b/tests/components/vizio/const.py index e3d09977c1f0..43605de67ad0 100644 --- a/tests/components/vizio/const.py +++ b/tests/components/vizio/const.py @@ -177,6 +177,7 @@ MOCK_INCLUDE_APPS = { CONF_INCLUDE_OR_EXCLUDE: CONF_INCLUDE.title(), CONF_APPS_TO_INCLUDE_OR_EXCLUDE: [CURRENT_APP], } + MOCK_INCLUDE_NO_APPS = { CONF_INCLUDE_OR_EXCLUDE: CONF_INCLUDE.title(), CONF_APPS_TO_INCLUDE_OR_EXCLUDE: [], diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index 3cb22a225417..0c057ba1a714 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -51,6 +51,7 @@ from .const import ( NAME2, UNIQUE_ID, VOLUME_STEP, + ZEROCONF_HOST, ) from tests.common import MockConfigEntry @@ -827,3 +828,28 @@ async def test_zeroconf_ignore( ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM + + +async def test_zeroconf_abort_when_ignored( + hass: HomeAssistantType, + vizio_connect: pytest.fixture, + vizio_bypass_setup: pytest.fixture, + vizio_guess_device_type: pytest.fixture, +) -> None: + """Test zeroconf discovery aborts when the same host has been ignored.""" + entry = MockConfigEntry( + domain=DOMAIN, + data=MOCK_SPEAKER_CONFIG, + options={CONF_VOLUME_STEP: VOLUME_STEP}, + source=SOURCE_IGNORE, + unique_id=ZEROCONF_HOST, + ) + entry.add_to_hass(hass) + + discovery_info = MOCK_ZEROCONF_SERVICE_INFO.copy() + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info + ) + + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == "already_configured"