Skip to content

Commit

Permalink
Handle errors in Fully Kiosk camera (#121659)
Browse files Browse the repository at this point in the history
  • Loading branch information
tronikos authored and frenck committed Jul 10, 2024
1 parent ec0910e commit ac3eecc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions homeassistant/components/fully_kiosk/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,8 +39,12 @@ async def async_camera_image(
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."""
Expand Down
7 changes: 7 additions & 0 deletions tests/components/fully_kiosk/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from unittest.mock import MagicMock

from fullykiosk import FullyKioskError
import pytest

from homeassistant.components.camera import async_get_image
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit ac3eecc

Please sign in to comment.