2019-03-24 16:16:50 +01:00
|
|
|
"""Axis camera platform tests."""
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2023-01-14 13:18:18 +01:00
|
|
|
import pytest
|
|
|
|
|
2020-06-01 18:45:38 +02:00
|
|
|
from homeassistant.components import camera
|
|
|
|
from homeassistant.components.axis.const import (
|
|
|
|
CONF_STREAM_PROFILE,
|
|
|
|
DOMAIN as AXIS_DOMAIN,
|
|
|
|
)
|
2020-05-14 10:49:27 +02:00
|
|
|
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
2020-10-22 09:29:53 +02:00
|
|
|
from homeassistant.const import STATE_IDLE
|
2023-02-08 12:16:23 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-12-08 15:44:04 +01:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2023-01-22 17:33:40 +01:00
|
|
|
from .const import NAME
|
2020-06-01 18:45:38 +02:00
|
|
|
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2023-02-08 12:16:23 +01:00
|
|
|
async def test_platform_manually_configured(hass: HomeAssistant) -> None:
|
2019-03-24 16:16:50 +01:00
|
|
|
"""Test that nothing happens when platform is manually configured."""
|
2019-07-31 12:25:30 -07:00
|
|
|
assert (
|
|
|
|
await async_setup_component(
|
2020-10-22 09:29:53 +02:00
|
|
|
hass, CAMERA_DOMAIN, {CAMERA_DOMAIN: {"platform": AXIS_DOMAIN}}
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2020-05-14 10:49:27 +02:00
|
|
|
assert AXIS_DOMAIN not in hass.data
|
2019-03-24 16:16:50 +01:00
|
|
|
|
|
|
|
|
2023-02-10 16:05:26 +01:00
|
|
|
async def test_camera(hass: HomeAssistant, setup_config_entry) -> None:
|
2019-03-24 16:16:50 +01:00
|
|
|
"""Test that Axis camera platform is loaded properly."""
|
2020-05-14 10:49:27 +02:00
|
|
|
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1
|
2019-03-24 16:16:50 +01:00
|
|
|
|
2020-10-22 09:29:53 +02:00
|
|
|
entity_id = f"{CAMERA_DOMAIN}.{NAME}"
|
|
|
|
|
|
|
|
cam = hass.states.get(entity_id)
|
|
|
|
assert cam.state == STATE_IDLE
|
2020-01-03 00:02:59 +01:00
|
|
|
assert cam.name == NAME
|
2020-06-01 18:45:38 +02:00
|
|
|
|
2020-10-22 09:29:53 +02:00
|
|
|
camera_entity = camera._get_camera_from_entity_id(hass, entity_id)
|
2020-06-01 18:45:38 +02:00
|
|
|
assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
|
|
|
|
assert camera_entity.mjpeg_source == "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi"
|
|
|
|
assert (
|
|
|
|
await camera_entity.stream_source()
|
|
|
|
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-01-15 04:12:03 +01:00
|
|
|
@pytest.mark.parametrize("options", [{CONF_STREAM_PROFILE: "profile_1"}])
|
2023-02-10 16:05:26 +01:00
|
|
|
async def test_camera_with_stream_profile(
|
|
|
|
hass: HomeAssistant, setup_config_entry
|
|
|
|
) -> None:
|
2020-06-01 18:45:38 +02:00
|
|
|
"""Test that Axis camera entity is using the correct path with stream profike."""
|
|
|
|
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1
|
|
|
|
|
2020-10-22 09:29:53 +02:00
|
|
|
entity_id = f"{CAMERA_DOMAIN}.{NAME}"
|
|
|
|
|
|
|
|
cam = hass.states.get(entity_id)
|
|
|
|
assert cam.state == STATE_IDLE
|
2020-06-01 18:45:38 +02:00
|
|
|
assert cam.name == NAME
|
|
|
|
|
2020-10-22 09:29:53 +02:00
|
|
|
camera_entity = camera._get_camera_from_entity_id(hass, entity_id)
|
2020-06-01 18:45:38 +02:00
|
|
|
assert camera_entity.image_source == "http://1.2.3.4:80/axis-cgi/jpg/image.cgi"
|
|
|
|
assert (
|
|
|
|
camera_entity.mjpeg_source
|
2021-01-23 00:15:58 +01:00
|
|
|
== "http://1.2.3.4:80/axis-cgi/mjpg/video.cgi?streamprofile=profile_1"
|
2020-06-01 18:45:38 +02:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
await camera_entity.stream_source()
|
|
|
|
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264&streamprofile=profile_1"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-02-10 16:05:26 +01:00
|
|
|
async def test_camera_disabled(hass: HomeAssistant, prepare_config_entry) -> None:
|
2020-06-01 18:45:38 +02:00
|
|
|
"""Test that Axis camera platform is loaded properly but does not create camera entity."""
|
2023-01-02 18:14:14 +01:00
|
|
|
with patch("axis.vapix.vapix.Params.image_format", new=None):
|
2023-01-22 17:33:40 +01:00
|
|
|
await prepare_config_entry()
|
2020-06-01 18:45:38 +02:00
|
|
|
|
|
|
|
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0
|