From f1556ead6d16710a020dd18fd842f5dbf92d5177 Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Sun, 12 Sep 2021 10:09:09 -0500 Subject: [PATCH] Don't cache HomeKit camera stream source from entity (#56136) --- .../components/homekit/type_cameras.py | 2 -- tests/components/homekit/test_type_cameras.py | 36 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/homekit/type_cameras.py b/homeassistant/components/homekit/type_cameras.py index 4a8999ede08..e0c9ad7de84 100644 --- a/homeassistant/components/homekit/type_cameras.py +++ b/homeassistant/components/homekit/type_cameras.py @@ -321,8 +321,6 @@ class Camera(HomeAccessory, PyhapCamera): _LOGGER.exception( "Failed to get stream source - this could be a transient error or your camera might not be compatible with HomeKit yet" ) - if stream_source: - self.config[CONF_STREAM_SOURCE] = stream_source return stream_source async def start_stream(self, session_info, stream_config): diff --git a/tests/components/homekit/test_type_cameras.py b/tests/components/homekit/test_type_cameras.py index 991965b30b5..b128cd44d07 100644 --- a/tests/components/homekit/test_type_cameras.py +++ b/tests/components/homekit/test_type_cameras.py @@ -317,29 +317,59 @@ async def test_camera_stream_source_found(hass, run_driver, events): assert acc.category == 17 # Camera await _async_setup_endpoints(hass, acc) + working_ffmpeg = _get_working_mock_ffmpeg() + session_info = acc.sessions[MOCK_START_STREAM_SESSION_UUID] with patch( "homeassistant.components.demo.camera.DemoCamera.stream_source", return_value="rtsp://example.local", ), patch( "homeassistant.components.homekit.type_cameras.HAFFmpeg", - return_value=_get_working_mock_ffmpeg(), + return_value=working_ffmpeg, ): await _async_start_streaming(hass, acc) await _async_stop_all_streams(hass, acc) + expected_output = ( + "-map 0:v:0 -an -c:v libx264 -profile:v high -tune zerolatency -pix_fmt " + "yuv420p -r 30 -b:v 299k -bufsize 1196k -maxrate 299k -payload_type 99 -ssrc {v_ssrc} -f " + "rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params " + "zdPmNLWeI86DtLJHvVLI6YPvqhVeeiLsNtrAgbgL " + "srtp://192.168.208.5:51246?rtcpport=51246&localrtcpport=51246&pkt_size=1316" + ) + + working_ffmpeg.open.assert_called_with( + cmd=[], + input_source="-i rtsp://example.local", + output=expected_output.format(**session_info), + stdout_pipe=False, + extra_cmd="-hide_banner -nostats", + stderr_pipe=True, + ) + await _async_setup_endpoints(hass, acc) + working_ffmpeg = _get_working_mock_ffmpeg() + session_info = acc.sessions[MOCK_START_STREAM_SESSION_UUID] with patch( "homeassistant.components.demo.camera.DemoCamera.stream_source", - return_value="rtsp://example.local", + return_value="rtsp://example2.local", ), patch( "homeassistant.components.homekit.type_cameras.HAFFmpeg", - return_value=_get_working_mock_ffmpeg(), + return_value=working_ffmpeg, ): await _async_start_streaming(hass, acc) await _async_stop_all_streams(hass, acc) + working_ffmpeg.open.assert_called_with( + cmd=[], + input_source="-i rtsp://example2.local", + output=expected_output.format(**session_info), + stdout_pipe=False, + extra_cmd="-hide_banner -nostats", + stderr_pipe=True, + ) + async def test_camera_stream_source_fails(hass, run_driver, events): """Test a camera that can stream and we cannot get the source from the entity."""