diff --git a/homeassistant/components/generic/config_flow.py b/homeassistant/components/generic/config_flow.py index 6e287c424b9..401b49dad4a 100644 --- a/homeassistant/components/generic/config_flow.py +++ b/homeassistant/components/generic/config_flow.py @@ -48,7 +48,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import UnknownFlow -from homeassistant.exceptions import TemplateError +from homeassistant.exceptions import HomeAssistantError, TemplateError from homeassistant.helpers import config_validation as cv, template as template_helper from homeassistant.helpers.httpx_client import get_async_client from homeassistant.util import slugify @@ -292,6 +292,10 @@ async def async_test_stream( if err.errno == EIO: # input/output error return {CONF_STREAM_SOURCE: "stream_io_error"} raise + except HomeAssistantError as err: + if "Stream integration is not set up" in str(err): + return {CONF_STREAM_SOURCE: "stream_not_set_up"} + raise return {} diff --git a/homeassistant/components/generic/strings.json b/homeassistant/components/generic/strings.json index 991a36d49cc..b05f17efc8d 100644 --- a/homeassistant/components/generic/strings.json +++ b/homeassistant/components/generic/strings.json @@ -15,6 +15,7 @@ "relative_url": "Relative URLs are not allowed", "template_error": "Error rendering template. Review log for more info.", "timeout": "Timeout while loading URL", + "stream_not_set_up": "The stream integration is not set up. Please ensure that you have 'default_config:' or 'stream:' in your configuration.yaml", "stream_no_route_to_host": "Could not find host while trying to connect to stream", "stream_io_error": "Input/Output error while trying to connect to stream. Wrong RTSP transport protocol?", "stream_not_permitted": "Operation not permitted while trying to connect to stream. Wrong RTSP transport protocol?" diff --git a/tests/components/generic/test_config_flow.py b/tests/components/generic/test_config_flow.py index c62142fb4d3..456e41a8d60 100644 --- a/tests/components/generic/test_config_flow.py +++ b/tests/components/generic/test_config_flow.py @@ -41,6 +41,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType +from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry @@ -597,7 +598,46 @@ async def test_form_stream_timeout( @respx.mock -@pytest.mark.usefixtures("fakeimg_png") +async def test_form_stream_not_set_up(hass: HomeAssistant, user_flow) -> None: + """Test we handle if stream has not been set up.""" + TESTDATA_ONLY_STREAM = TESTDATA.copy() + TESTDATA_ONLY_STREAM.pop(CONF_STILL_IMAGE_URL) + + with patch( + "homeassistant.components.generic.config_flow.create_stream", + side_effect=HomeAssistantError("Stream integration is not set up."), + ): + result1 = await hass.config_entries.flow.async_configure( + user_flow["flow_id"], + TESTDATA_ONLY_STREAM, + ) + await hass.async_block_till_done() + + assert result1["type"] is FlowResultType.FORM + assert result1["errors"] == {"stream_source": "stream_not_set_up"} + + +@respx.mock +async def test_form_stream_other_error(hass: HomeAssistant, user_flow) -> None: + """Test the unknown error for streams.""" + TESTDATA_ONLY_STREAM = TESTDATA.copy() + TESTDATA_ONLY_STREAM.pop(CONF_STILL_IMAGE_URL) + + with ( + patch( + "homeassistant.components.generic.config_flow.create_stream", + side_effect=HomeAssistantError("Some other error."), + ), + pytest.raises(HomeAssistantError), + ): + await hass.config_entries.flow.async_configure( + user_flow["flow_id"], + TESTDATA_ONLY_STREAM, + ) + await hass.async_block_till_done() + + +@respx.mock async def test_form_stream_worker_error( hass: HomeAssistant, user_flow: ConfigFlowResult ) -> None: