diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index d31d21d424c..b6bf794a05f 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -896,7 +896,7 @@ class Camera(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): else: frontend_stream_types.add(StreamType.HLS) - if self._webrtc_provider: + if self._webrtc_provider or self._legacy_webrtc_provider: frontend_stream_types.add(StreamType.WEB_RTC) return CameraCapabilities(frontend_stream_types) diff --git a/homeassistant/components/camera/media_source.py b/homeassistant/components/camera/media_source.py index ea30dafb09e..222c95ff998 100644 --- a/homeassistant/components/camera/media_source.py +++ b/homeassistant/components/camera/media_source.py @@ -64,7 +64,7 @@ class CameraMediaSource(MediaSource): if not camera: raise Unresolvable(f"Could not resolve media item: {item.identifier}") - if (stream_type := camera.frontend_stream_type) is None: + if not (stream_types := camera.camera_capabilities.frontend_stream_types): return PlayMedia( f"/api/camera_proxy_stream/{camera.entity_id}", camera.content_type ) @@ -76,7 +76,7 @@ class CameraMediaSource(MediaSource): url = await _async_stream_endpoint_url(self.hass, camera, HLS_PROVIDER) except HomeAssistantError as err: # Handle known error - if stream_type != StreamType.HLS: + if StreamType.HLS not in stream_types: raise Unresolvable( "Camera does not support MJPEG or HLS streaming." ) from err diff --git a/homeassistant/components/camera/webrtc.py b/homeassistant/components/camera/webrtc.py index d627a888169..f43e86fad38 100644 --- a/homeassistant/components/camera/webrtc.py +++ b/homeassistant/components/camera/webrtc.py @@ -230,13 +230,15 @@ def require_webrtc_support( """Validate that the camera supports WebRTC.""" entity_id = msg["entity_id"] camera = get_camera_from_entity_id(hass, entity_id) - if camera.frontend_stream_type != StreamType.WEB_RTC: + if StreamType.WEB_RTC not in ( + stream_types := camera.camera_capabilities.frontend_stream_types + ): connection.send_error( msg["id"], error_code, ( "Camera does not support WebRTC," - f" frontend_stream_type={camera.frontend_stream_type}" + f" frontend_stream_types={stream_types}" ), ) return diff --git a/tests/components/camera/test_webrtc.py b/tests/components/camera/test_webrtc.py index 29fb9d61c4e..be9f3aae6d7 100644 --- a/tests/components/camera/test_webrtc.py +++ b/tests/components/camera/test_webrtc.py @@ -417,7 +417,7 @@ async def test_ws_get_client_config_no_rtc_camera( assert not msg["success"] assert msg["error"] == { "code": "webrtc_get_client_config_failed", - "message": "Camera does not support WebRTC, frontend_stream_type=hls", + "message": "Camera does not support WebRTC, frontend_stream_types={}", } @@ -747,7 +747,7 @@ async def test_websocket_webrtc_offer_invalid_stream_type( assert not response["success"] assert response["error"] == { "code": "webrtc_offer_failed", - "message": "Camera does not support WebRTC, frontend_stream_type=hls", + "message": "Camera does not support WebRTC, frontend_stream_types={}", } @@ -800,45 +800,6 @@ async def mock_hls_stream_source_fixture() -> AsyncGenerator[AsyncMock]: yield mock_hls_stream_source -@pytest.mark.usefixtures( - "mock_camera", - "mock_hls_stream_source", # Not an RTSP stream source - "mock_camera_webrtc_frontendtype_only", -) -async def test_unsupported_rtsp_to_webrtc_stream_type( - hass: HomeAssistant, hass_ws_client: WebSocketGenerator -) -> None: - """Test rtsp-to-webrtc is not registered for non-RTSP streams.""" - client = await hass_ws_client(hass) - await client.send_json_auto_id( - { - "type": "camera/webrtc/offer", - "entity_id": "camera.demo_camera", - "offer": WEBRTC_OFFER, - } - ) - response = await client.receive_json() - assert response["type"] == TYPE_RESULT - assert response["success"] - subscription_id = response["id"] - - # Session id - response = await client.receive_json() - assert response["id"] == subscription_id - assert response["type"] == "event" - assert response["event"]["type"] == "session" - - # Answer - response = await client.receive_json() - assert response["id"] == subscription_id - assert response["type"] == "event" - assert response["event"] == { - "type": "error", - "code": "webrtc_offer_failed", - "message": "Camera does not support WebRTC", - } - - @pytest.mark.usefixtures("mock_camera", "mock_stream_source") async def test_rtsp_to_webrtc_provider_unregistered( hass: HomeAssistant, hass_ws_client: WebSocketGenerator @@ -894,7 +855,7 @@ async def test_rtsp_to_webrtc_provider_unregistered( assert not response["success"] assert response["error"] == { "code": "webrtc_offer_failed", - "message": "Camera does not support WebRTC, frontend_stream_type=hls", + "message": "Camera does not support WebRTC, frontend_stream_types={}", } assert not mock_provider.called @@ -1093,7 +1054,7 @@ async def test_ws_webrtc_candidate_invalid_stream_type( assert not response["success"] assert response["error"] == { "code": "webrtc_candidate_failed", - "message": "Camera does not support WebRTC, frontend_stream_type=hls", + "message": "Camera does not support WebRTC, frontend_stream_types={}", } diff --git a/tests/components/go2rtc/test_init.py b/tests/components/go2rtc/test_init.py index 0f1cac6942d..dba3b4d3a54 100644 --- a/tests/components/go2rtc/test_init.py +++ b/tests/components/go2rtc/test_init.py @@ -211,7 +211,7 @@ async def _test_setup_and_signaling( ) -> None: """Test the go2rtc config entry.""" entity_id = camera.entity_id - assert camera.frontend_stream_type == StreamType.HLS + assert camera.camera_capabilities.frontend_stream_types == {StreamType.HLS} assert await async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done(wait_background_tasks=True) diff --git a/tests/components/nest/test_camera.py b/tests/components/nest/test_camera.py index 029879f1413..eb15b998507 100644 --- a/tests/components/nest/test_camera.py +++ b/tests/components/nest/test_camera.py @@ -745,7 +745,7 @@ async def test_camera_web_rtc_unsupported( assert not msg["success"] assert msg["error"] == { "code": "webrtc_offer_failed", - "message": "Camera does not support WebRTC, frontend_stream_type=hls", + "message": "Camera does not support WebRTC, frontend_stream_types={}", }