mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Fix Camera Proxy not returning the last image when the source camera fails (#192759)
This commit is contained in:
@@ -271,8 +271,10 @@ class ProxyCamera(Camera):
|
||||
return self._last_image
|
||||
|
||||
self._last_image_time = now
|
||||
image = await async_get_image(self.hass, self._proxied_camera)
|
||||
if not image:
|
||||
try:
|
||||
image = await async_get_image(self.hass, self._proxied_camera)
|
||||
# pylint: disable-next=home-assistant-action-swallowed-exception
|
||||
except HomeAssistantError:
|
||||
_LOGGER.error("Error getting original camera image")
|
||||
return self._last_image
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
from homeassistant.components.camera import Image, async_get_image
|
||||
from homeassistant.components.proxy.camera import ProxyCamera
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
CROP_CONFIG = {
|
||||
@@ -81,3 +82,25 @@ async def test_crop_stream_after_small_frame(
|
||||
if b"\r\n\r\n" in part
|
||||
]
|
||||
assert _size(frames[-1]) == (400, 225)
|
||||
|
||||
|
||||
async def test_image_return_cached_image_on_error(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the last cached image is returned when the source camera fails."""
|
||||
assert await async_setup_component(
|
||||
hass, "camera", {"camera": {**CROP_CONFIG, "cache_images": True}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.proxy.camera.async_get_image",
|
||||
AsyncMock(
|
||||
side_effect=[_jpeg(1536, 576), HomeAssistantError("Unable to get image")]
|
||||
),
|
||||
):
|
||||
first = await async_get_image(hass, "camera.cropped")
|
||||
second = await async_get_image(hass, "camera.cropped")
|
||||
|
||||
assert second.content == first.content
|
||||
assert "Error getting original camera image" in caplog.text
|
||||
|
||||
Reference in New Issue
Block a user