Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/prosegur/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ async def async_camera_image(
) -> bytes | None:
"""Return bytes of camera image."""

_LOGGER.debug("Get image for %s", self._camera.description)
Comment thread
MartinHjelmare marked this conversation as resolved.
try:
_LOGGER.debug("Get image for %s", self._camera.description)
return await self._installation.get_image(self._auth, self._camera.id)

except ProsegurException as err:
Expand Down
9 changes: 6 additions & 3 deletions tests/components/prosegur/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Define test fixtures for Prosegur."""
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch

from pyprosegur.installation import Camera
import pytest
Expand Down Expand Up @@ -30,9 +30,12 @@ def mock_config_entry() -> MockConfigEntry:
@pytest.fixture
def mock_install() -> AsyncMock:
"""Return the mocked alarm install."""
install = AsyncMock()
install = MagicMock()
install.contract = CONTRACT
install.cameras = [Camera("1", "test_cam")]
install.arm = AsyncMock()
install.disarm = AsyncMock()
install.arm_partially = AsyncMock()
install.get_image = AsyncMock(return_value=b"ABC")
install.request_image = AsyncMock()

Expand All @@ -51,7 +54,7 @@ async def init_integration(

with patch(
"pyprosegur.installation.Installation.retrieve", return_value=mock_install
), patch("pyprosegur.auth.Auth.login", return_value=AsyncMock()):
), patch("pyprosegur.auth.Auth.login"):
await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()

Expand Down
7 changes: 2 additions & 5 deletions tests/components/prosegur/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ async def test_camera_fail(hass, init_integration, mock_install, caplog):
)

with caplog.at_level(logging.ERROR, logger="homeassistant.components.prosegur"):
try:
with pytest.raises(HomeAssistantError) as exc:
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await camera.async_get_image(hass, "camera.test_cam")
except HomeAssistantError as exc:
assert str(exc) == "Unable to get image"
else:
assert pytest.fail()
assert "Unable to get image" in str(exc.value)

assert "Image test_cam doesn't exist" in caplog.text

Expand Down