mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Handle errors in Fully Kiosk camera (#121659)
This commit is contained in:
parent
42003ae5ac
commit
1925614a14
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from fullykiosk import FullyKioskError
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera, CameraEntityFeature
|
from homeassistant.components.camera import Camera, CameraEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -36,8 +39,12 @@ class FullyCameraEntity(FullyKioskEntity, Camera):
|
|||||||
self, width: int | None = None, height: int | None = None
|
self, width: int | None = None, height: int | None = None
|
||||||
) -> bytes | None:
|
) -> bytes | None:
|
||||||
"""Return bytes of camera image."""
|
"""Return bytes of camera image."""
|
||||||
image_bytes: bytes = await self.coordinator.fully.getCamshot()
|
try:
|
||||||
return image_bytes
|
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:
|
async def async_turn_on(self) -> None:
|
||||||
"""Turn on camera."""
|
"""Turn on camera."""
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from fullykiosk import FullyKioskError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.camera import async_get_image
|
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 mock_fully_kiosk.getCamshot.call_count == 1
|
||||||
assert image.content == b"image_bytes"
|
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}
|
mock_fully_kiosk.getSettings.return_value = {"motionDetection": False}
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"camera",
|
"camera",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user