mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Update go2rtc stream if stream_source is not matching (#129804)
This commit is contained in:
parent
0f0f5fd0ab
commit
7084b3b52c
@ -203,15 +203,17 @@ class WebRTCProvider(CameraWebRTCProvider):
|
|||||||
self._session, self._url, source=camera.entity_id
|
self._session, self._url, source=camera.entity_id
|
||||||
)
|
)
|
||||||
|
|
||||||
streams = await self._rest_client.streams.list()
|
|
||||||
if camera.entity_id not in streams:
|
|
||||||
if not (stream_source := await camera.stream_source()):
|
if not (stream_source := await camera.stream_source()):
|
||||||
send_message(
|
send_message(
|
||||||
WebRTCError(
|
WebRTCError("go2rtc_webrtc_offer_failed", "Camera has no stream source")
|
||||||
"go2rtc_webrtc_offer_failed", "Camera has no stream source"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
streams = await self._rest_client.streams.list()
|
||||||
|
|
||||||
|
if (stream := streams.get(camera.entity_id)) is None or not any(
|
||||||
|
stream_source == producer.url for producer in stream.producers
|
||||||
|
):
|
||||||
await self._rest_client.streams.add(camera.entity_id, stream_source)
|
await self._rest_client.streams.add(camera.entity_id, stream_source)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -21,7 +21,8 @@ def rest_client() -> Generator[AsyncMock]:
|
|||||||
patch("homeassistant.components.go2rtc.server.Go2RtcRestClient", mock_client),
|
patch("homeassistant.components.go2rtc.server.Go2RtcRestClient", mock_client),
|
||||||
):
|
):
|
||||||
client = mock_client.return_value
|
client = mock_client.return_value
|
||||||
client.streams = Mock(spec_set=_StreamClient)
|
client.streams = streams = Mock(spec_set=_StreamClient)
|
||||||
|
streams.list.return_value = {}
|
||||||
client.webrtc = Mock(spec_set=_WebRTCClient)
|
client.webrtc = Mock(spec_set=_WebRTCClient)
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
@ -239,6 +239,18 @@ async def _test_setup_and_signaling(
|
|||||||
|
|
||||||
rest_client.streams.add.assert_called_once_with(entity_id, "rtsp://stream")
|
rest_client.streams.add.assert_called_once_with(entity_id, "rtsp://stream")
|
||||||
|
|
||||||
|
# Stream exists but the source is different
|
||||||
|
rest_client.streams.add.reset_mock()
|
||||||
|
rest_client.streams.list.return_value = {
|
||||||
|
entity_id: Stream([Producer("rtsp://different")])
|
||||||
|
}
|
||||||
|
|
||||||
|
receive_message_callback.reset_mock()
|
||||||
|
ws_client.reset_mock()
|
||||||
|
await test()
|
||||||
|
|
||||||
|
rest_client.streams.add.assert_called_once_with(entity_id, "rtsp://stream")
|
||||||
|
|
||||||
# If the stream is already added, the stream should not be added again.
|
# If the stream is already added, the stream should not be added again.
|
||||||
rest_client.streams.add.reset_mock()
|
rest_client.streams.add.reset_mock()
|
||||||
rest_client.streams.list.return_value = {
|
rest_client.streams.list.return_value = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user