Improve user message if stream is not set up in generic camera (#121308)

This commit is contained in:
Dave T 2024-07-06 09:50:16 +01:00 committed by GitHub
parent 18370bdbb4
commit a358609609
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 2 deletions

View file

@ -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 {}

View file

@ -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?"

View file

@ -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: