Translate camera stream not supported error (#184576)

This commit is contained in:
Franck Nijhof
2026-10-07 08:01:04 +02:00
committed by GitHub
parent 74c9417581
commit efb76092b6
5 changed files with 24 additions and 8 deletions
+8 -1
View File
@@ -914,7 +914,14 @@ async def ws_camera_stream(
connection.send_result(msg["id"], {"url": url})
except HomeAssistantError as ex:
_LOGGER.error("Error requesting stream: %s", ex)
connection.send_error(msg["id"], "start_stream_failed", str(ex))
connection.send_error(
msg["id"],
"start_stream_failed",
str(ex),
translation_domain=ex.translation_domain,
translation_key=ex.translation_key,
translation_placeholders=ex.translation_placeholders,
)
except TimeoutError:
_LOGGER.error("Timeout getting stream source")
connection.send_error(
+4 -2
View File
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from .const import DATA_COMPONENT, CameraEntityFeature
from .const import DATA_COMPONENT, DOMAIN, CameraEntityFeature
if TYPE_CHECKING:
from . import Camera
@@ -53,7 +53,9 @@ async def async_stream_endpoint_url(
stream = await camera.async_create_stream()
if not stream:
raise HomeAssistantError(
f"{camera.entity_id} does not support play stream service"
translation_domain=DOMAIN,
translation_key="stream_not_supported",
translation_placeholders={"entity_id": camera.entity_id},
)
stream.add_provider(fmt)
@@ -44,6 +44,9 @@
"snapshot_timeout": {
"message": "Unable to get snapshot: timed out after {timeout} seconds."
},
"stream_not_supported": {
"message": "Camera {entity_id} does not support streaming."
},
"write_failed": {
"message": "Cannot write image to {filename}."
},
+1 -3
View File
@@ -146,6 +146,4 @@ async def test_resolving_errors(hass: HomeAssistant) -> None:
await media_source.async_resolve_media(
hass, "media-source://camera/camera.demo_camera", None
)
assert (
str(exc_info.value) == "camera.demo_camera does not support play stream service"
)
assert str(exc_info.value) == "Camera camera.demo_camera does not support streaming"
+8 -2
View File
@@ -422,7 +422,10 @@ async def test_stream_source_error(
assert msg["success"] is False
assert msg["error"] == {
"code": "start_stream_failed",
"message": "camera.config_test does not support play stream service",
"message": "Camera camera.config_test does not support streaming",
"translation_domain": "camera",
"translation_key": "stream_not_supported",
"translation_placeholders": {"entity_id": "camera.config_test"},
}
@@ -484,7 +487,10 @@ async def test_no_stream_source(
assert msg["success"] is False
assert msg["error"] == {
"code": "start_stream_failed",
"message": "camera.config_test does not support play stream service",
"message": "Camera camera.config_test does not support streaming",
"translation_domain": "camera",
"translation_key": "stream_not_supported",
"translation_placeholders": {"entity_id": "camera.config_test"},
}