From f2d2b90c116ea786346ce6d346a557a8dd0101fa Mon Sep 17 00:00:00 2001 From: raman325 <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:04:59 -0500 Subject: [PATCH 1/3] abort vizio discovery flow if unique ID cant be found because it means we cant connect --- homeassistant/components/vizio/config_flow.py | 4 ++++ homeassistant/components/vizio/strings.json | 1 + 2 files changed, 5 insertions(+) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index f3b7720a33e570..24a20e028b77fb 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -367,6 +367,10 @@ async def async_step_zeroconf( discovery_info[CONF_DEVICE_CLASS], session=async_get_clientsession(self.hass, False), ) + + if not unique_id: + return self.async_abort("cannot_connect") + await self.async_set_unique_id(unique_id=unique_id, raise_on_progress=True) self._abort_if_unique_id_configured() diff --git a/homeassistant/components/vizio/strings.json b/homeassistant/components/vizio/strings.json index da039b6a89e5e5..adad8406da0072 100644 --- a/homeassistant/components/vizio/strings.json +++ b/homeassistant/components/vizio/strings.json @@ -34,6 +34,7 @@ }, "abort": { "already_configured_device": "[%key:common::config_flow::abort::already_configured_device%]", + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", "updated_entry": "This entry has already been setup but the name, apps, and/or options defined in the configuration do not match the previously imported configuration, so the configuration entry has been updated accordingly." } }, From 6b9f9437f3be79a5dd6bcac7ab9a191cefc0c552 Mon Sep 17 00:00:00 2001 From: raman325 <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:21:55 -0500 Subject: [PATCH 2/3] add tests --- tests/components/vizio/test_config_flow.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index 5cbc2fa55645d4..4c9ba3e9928085 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -826,6 +826,21 @@ async def test_zeroconf_ignore( assert result["type"] == data_entry_flow.RESULT_TYPE_FORM +async def test_zeroconf_no_unique_id( + hass: HomeAssistantType, + vizio_no_unique_id: pytest.fixture, +) -> None: + """Test zeroconf discovery aborts when unique_id is None.""" + + 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"] == "cannot_connect" + + async def test_zeroconf_abort_when_ignored( hass: HomeAssistantType, vizio_connect: pytest.fixture, From e2a2e997fc1f3236fd96c7dafdef441685bf05b2 Mon Sep 17 00:00:00 2001 From: raman325 <7243222+raman325@users.noreply.github.com> Date: Mon, 16 Nov 2020 23:45:32 -0500 Subject: [PATCH 3/3] fix abort call --- homeassistant/components/vizio/config_flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index 24a20e028b77fb..908b66b5e3421d 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -369,7 +369,7 @@ async def async_step_zeroconf( ) if not unique_id: - return self.async_abort("cannot_connect") + return self.async_abort(reason="cannot_connect") await self.async_set_unique_id(unique_id=unique_id, raise_on_progress=True) self._abort_if_unique_id_configured()