Add support for attribute caching to the camera platform (#106256)

This commit is contained in:
J. Nick Koston
2023-12-23 13:01:47 -10:00
committed by GitHub
parent 2f72d4f9f0
commit abd3c54cbe
5 changed files with 48 additions and 40 deletions

View File

@@ -58,10 +58,7 @@ async def mock_stream_source_fixture():
with patch(
"homeassistant.components.camera.Camera.stream_source",
return_value=STREAM_SOURCE,
) as mock_stream_source, patch(
"homeassistant.components.camera.Camera.supported_features",
return_value=camera.CameraEntityFeature.STREAM,
):
) as mock_stream_source:
yield mock_stream_source
@@ -71,10 +68,7 @@ async def mock_hls_stream_source_fixture():
with patch(
"homeassistant.components.camera.Camera.stream_source",
return_value=HLS_STREAM_SOURCE,
) as mock_hls_stream_source, patch(
"homeassistant.components.camera.Camera.supported_features",
return_value=camera.CameraEntityFeature.STREAM,
):
) as mock_hls_stream_source:
yield mock_hls_stream_source
@@ -934,19 +928,15 @@ async def test_use_stream_for_stills(
return_value=True,
):
# First test when the integration does not support stream should fail
resp = await client.get("/api/camera_proxy/camera.demo_camera")
resp = await client.get("/api/camera_proxy/camera.demo_camera_without_stream")
await hass.async_block_till_done()
mock_stream_source.assert_not_called()
assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR
# Test when the integration does not provide a stream_source should fail
with patch(
"homeassistant.components.demo.camera.DemoCamera.supported_features",
return_value=camera.CameraEntityFeature.STREAM,
):
resp = await client.get("/api/camera_proxy/camera.demo_camera")
await hass.async_block_till_done()
mock_stream_source.assert_called_once()
assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR
resp = await client.get("/api/camera_proxy/camera.demo_camera")
await hass.async_block_till_done()
mock_stream_source.assert_called_once()
assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR
with patch(
"homeassistant.components.demo.camera.DemoCamera.stream_source",
@@ -954,9 +944,6 @@ async def test_use_stream_for_stills(
) as mock_stream_source, patch(
"homeassistant.components.camera.create_stream"
) as mock_create_stream, patch(
"homeassistant.components.demo.camera.DemoCamera.supported_features",
return_value=camera.CameraEntityFeature.STREAM,
), patch(
"homeassistant.components.demo.camera.DemoCamera.use_stream_for_stills",
return_value=True,
):