2020-03-15 19:05:10 -07:00
|
|
|
"""Tests for the Abode camera device."""
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2020-03-15 19:05:10 -07:00
|
|
|
from homeassistant.components.abode.const import DOMAIN as ABODE_DOMAIN
|
|
|
|
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
|
|
|
from homeassistant.const import ATTR_ENTITY_ID, STATE_IDLE
|
2022-01-10 09:54:09 -05:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-03-09 14:24:34 +01:00
|
|
|
from homeassistant.helpers import entity_registry as er
|
2020-03-15 19:05:10 -07:00
|
|
|
|
|
|
|
from .common import setup_platform
|
|
|
|
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
async def test_entity_registry(hass: HomeAssistant) -> None:
|
2020-03-15 19:05:10 -07:00
|
|
|
"""Tests that the devices are registered in the entity registry."""
|
|
|
|
await setup_platform(hass, CAMERA_DOMAIN)
|
2021-03-09 14:24:34 +01:00
|
|
|
entity_registry = er.async_get(hass)
|
2020-03-15 19:05:10 -07:00
|
|
|
|
|
|
|
entry = entity_registry.async_get("camera.test_cam")
|
|
|
|
assert entry.unique_id == "d0a3a1c316891ceb00c20118aae2a133"
|
|
|
|
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
async def test_attributes(hass: HomeAssistant) -> None:
|
2020-03-15 19:05:10 -07:00
|
|
|
"""Test the camera attributes are correct."""
|
|
|
|
await setup_platform(hass, CAMERA_DOMAIN)
|
|
|
|
|
|
|
|
state = hass.states.get("camera.test_cam")
|
|
|
|
assert state.state == STATE_IDLE
|
|
|
|
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
async def test_capture_image(hass: HomeAssistant) -> None:
|
2020-03-15 19:05:10 -07:00
|
|
|
"""Test the camera capture image service."""
|
|
|
|
await setup_platform(hass, CAMERA_DOMAIN)
|
|
|
|
|
|
|
|
with patch("abodepy.AbodeCamera.capture") as mock_capture:
|
|
|
|
await hass.services.async_call(
|
|
|
|
ABODE_DOMAIN,
|
|
|
|
"capture_image",
|
|
|
|
{ATTR_ENTITY_ID: "camera.test_cam"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
mock_capture.assert_called_once()
|
2020-07-26 11:59:11 -07:00
|
|
|
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
async def test_camera_on(hass: HomeAssistant) -> None:
|
2020-07-26 11:59:11 -07:00
|
|
|
"""Test the camera turn on service."""
|
|
|
|
await setup_platform(hass, CAMERA_DOMAIN)
|
|
|
|
|
|
|
|
with patch("abodepy.AbodeCamera.privacy_mode") as mock_capture:
|
|
|
|
await hass.services.async_call(
|
|
|
|
CAMERA_DOMAIN,
|
|
|
|
"turn_on",
|
|
|
|
{ATTR_ENTITY_ID: "camera.test_cam"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
mock_capture.assert_called_once_with(False)
|
|
|
|
|
|
|
|
|
2022-01-10 09:54:09 -05:00
|
|
|
async def test_camera_off(hass: HomeAssistant) -> None:
|
2020-07-26 11:59:11 -07:00
|
|
|
"""Test the camera turn off service."""
|
|
|
|
await setup_platform(hass, CAMERA_DOMAIN)
|
|
|
|
|
|
|
|
with patch("abodepy.AbodeCamera.privacy_mode") as mock_capture:
|
|
|
|
await hass.services.async_call(
|
|
|
|
CAMERA_DOMAIN,
|
|
|
|
"turn_off",
|
|
|
|
{ATTR_ENTITY_ID: "camera.test_cam"},
|
|
|
|
blocking=True,
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
mock_capture.assert_called_once_with(True)
|