diff --git a/homeassistant/components/ipp/config_flow.py b/homeassistant/components/ipp/config_flow.py index 3128583f218..ba12d7ec8e2 100644 --- a/homeassistant/components/ipp/config_flow.py +++ b/homeassistant/components/ipp/config_flow.py @@ -85,12 +85,12 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN): unique_id = user_input[CONF_UUID] = info[CONF_UUID] - if unique_id is None and info[CONF_SERIAL] is not None: + if not unique_id and info[CONF_SERIAL]: _LOGGER.debug( "Printer UUID is missing from IPP response. Falling back to IPP serial number" ) unique_id = info[CONF_SERIAL] - elif unique_id is None: + elif not unique_id: _LOGGER.debug("Unable to determine unique id from IPP response") await self.async_set_unique_id(unique_id) @@ -138,17 +138,17 @@ class IPPFlowHandler(ConfigFlow, domain=DOMAIN): return self.async_abort(reason="ipp_error") unique_id = self.discovery_info[CONF_UUID] - if unique_id is None and info[CONF_UUID] is not None: + if not unique_id and info[CONF_UUID]: _LOGGER.debug( "Printer UUID is missing from discovery info. Falling back to IPP UUID" ) unique_id = self.discovery_info[CONF_UUID] = info[CONF_UUID] - elif unique_id is None and info[CONF_SERIAL] is not None: + elif not unique_id and info[CONF_SERIAL]: _LOGGER.debug( "Printer UUID is missing from discovery info and IPP response. Falling back to IPP serial number" ) unique_id = info[CONF_SERIAL] - elif unique_id is None: + elif not unique_id: _LOGGER.debug( "Unable to determine unique id from discovery info and IPP response" ) diff --git a/tests/components/ipp/test_config_flow.py b/tests/components/ipp/test_config_flow.py index 0093ba57e5b..a468115f239 100644 --- a/tests/components/ipp/test_config_flow.py +++ b/tests/components/ipp/test_config_flow.py @@ -264,6 +264,24 @@ async def test_zeroconf_with_uuid_device_exists_abort( assert result["reason"] == "already_configured" +async def test_zeroconf_empty_unique_id_required_abort( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: + """Test we abort zeroconf flow if printer lacks (empty) unique identification.""" + mock_connection(aioclient_mock, no_unique_id=True) + + discovery_info = { + **MOCK_ZEROCONF_IPP_SERVICE_INFO, + "properties": {**MOCK_ZEROCONF_IPP_SERVICE_INFO["properties"], "UUID": ""}, + } + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_ZEROCONF}, data=discovery_info, + ) + + assert result["type"] == RESULT_TYPE_ABORT + assert result["reason"] == "unique_id_required" + + async def test_zeroconf_unique_id_required_abort( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: