From f44ca5f9d501d973cfde24205da835d2345cae1b Mon Sep 17 00:00:00 2001 From: Dave T <17680170+davet2001@users.noreply.github.com> Date: Tue, 8 Feb 2022 22:47:36 +0000 Subject: [PATCH] Fix generic camera typo in attr_frame_interval (#65390) --- homeassistant/components/generic/camera.py | 2 +- tests/components/generic/test_camera.py | 27 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/generic/camera.py b/homeassistant/components/generic/camera.py index b6084d148a3..b4aaad38618 100644 --- a/homeassistant/components/generic/camera.py +++ b/homeassistant/components/generic/camera.py @@ -96,7 +96,7 @@ class GenericCamera(Camera): if self._stream_source is not None: self._stream_source.hass = hass self._limit_refetch = device_info[CONF_LIMIT_REFETCH_TO_URL_CHANGE] - self._attr_frames_interval = 1 / device_info[CONF_FRAMERATE] + self._attr_frame_interval = 1 / device_info[CONF_FRAMERATE] self._supported_features = SUPPORT_STREAM if self._stream_source else 0 self.content_type = device_info[CONF_CONTENT_TYPE] self.verify_ssl = device_info[CONF_VERIFY_SSL] diff --git a/tests/components/generic/test_camera.py b/tests/components/generic/test_camera.py index 60e68a1e7b1..042cd2ee650 100644 --- a/tests/components/generic/test_camera.py +++ b/tests/components/generic/test_camera.py @@ -9,6 +9,7 @@ import pytest import respx from homeassistant import config as hass_config +from homeassistant.components.camera import async_get_mjpeg_stream from homeassistant.components.generic import DOMAIN from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.const import SERVICE_RELOAD @@ -515,3 +516,29 @@ async def test_no_still_image_url(hass, hass_client): mock_stream.async_get_image.assert_called_once() assert resp.status == HTTPStatus.OK assert await resp.read() == b"stream_keyframe_image" + + +async def test_frame_interval_property(hass): + """Test that the frame interval is calculated and returned correctly.""" + + await async_setup_component( + hass, + "camera", + { + "camera": { + "name": "config_test", + "platform": "generic", + "stream_source": "rtsp://example.com:554/rtsp/", + "framerate": 5, + }, + }, + ) + await hass.async_block_till_done() + + request = Mock() + with patch( + "homeassistant.components.camera.async_get_still_stream" + ) as mock_get_stream: + await async_get_mjpeg_stream(hass, request, "camera.config_test") + + assert mock_get_stream.call_args_list[0][0][3] == pytest.approx(0.2)