diff --git a/homeassistant/components/vizio/config_flow.py b/homeassistant/components/vizio/config_flow.py index b6d6d9bfb05..40f71adda12 100644 --- a/homeassistant/components/vizio/config_flow.py +++ b/homeassistant/components/vizio/config_flow.py @@ -369,6 +369,10 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): discovery_info[CONF_DEVICE_CLASS], session=async_get_clientsession(self.hass, False), ) + + if not unique_id: + 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() diff --git a/homeassistant/components/vizio/strings.json b/homeassistant/components/vizio/strings.json index da039b6a89e..adad8406da0 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." } }, diff --git a/tests/components/vizio/test_config_flow.py b/tests/components/vizio/test_config_flow.py index 32469fabd05..e966188afd2 100644 --- a/tests/components/vizio/test_config_flow.py +++ b/tests/components/vizio/test_config_flow.py @@ -856,6 +856,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,