Handle errors in Fully Kiosk camera (#121659)

This commit is contained in:
tronikos 2024-07-10 02:21:38 -07:00 committed by GitHub
parent 42003ae5ac
commit 1925614a14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View file

@ -2,9 +2,12 @@
from __future__ import annotations
from fullykiosk import FullyKioskError
from homeassistant.components.camera import Camera, CameraEntityFeature
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
@ -36,8 +39,12 @@ class FullyCameraEntity(FullyKioskEntity, Camera):
self, width: int | None = None, height: int | None = None
) -> bytes | None:
"""Return bytes of camera image."""
image_bytes: bytes = await self.coordinator.fully.getCamshot()
return image_bytes
try:
image_bytes: bytes = await self.coordinator.fully.getCamshot()
except FullyKioskError as err:
raise HomeAssistantError(err) from err
else:
return image_bytes
async def async_turn_on(self) -> None:
"""Turn on camera."""

View file

@ -2,6 +2,7 @@
from unittest.mock import MagicMock
from fullykiosk import FullyKioskError
import pytest
from homeassistant.components.camera import async_get_image
@ -41,6 +42,12 @@ async def test_camera(
assert mock_fully_kiosk.getCamshot.call_count == 1
assert image.content == b"image_bytes"
fully_kiosk_error = FullyKioskError("error", "status")
mock_fully_kiosk.getCamshot.side_effect = fully_kiosk_error
with pytest.raises(HomeAssistantError) as error:
await async_get_image(hass, entity_camera)
assert error.value.args[0] == fully_kiosk_error
mock_fully_kiosk.getSettings.return_value = {"motionDetection": False}
await hass.services.async_call(
"camera",