core/tests/components/axis/test_camera.py

81 lines
2.7 KiB
Python
Raw Normal View History

"""Axis camera platform tests."""
2021-01-01 21:31:56 +00:00
from unittest.mock import patch
from homeassistant.components import camera
from homeassistant.components.axis.const import (
CONF_STREAM_PROFILE,
DOMAIN as AXIS_DOMAIN,
)
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
2020-10-22 07:29:53 +00:00
from homeassistant.const import STATE_IDLE
from homeassistant.setup import async_setup_component
from .test_device import ENTRY_OPTIONS, NAME, setup_axis_integration
async def test_platform_manually_configured(hass):
"""Test that nothing happens when platform is manually configured."""
2019-07-31 19:25:30 +00:00
assert (
await async_setup_component(
2020-10-22 07:29:53 +00:00
hass, CAMERA_DOMAIN, {CAMERA_DOMAIN: {"platform": AXIS_DOMAIN}}
2019-07-31 19:25:30 +00:00
)
is True
)
assert AXIS_DOMAIN not in hass.data
async def test_camera(hass):
"""Test that Axis camera platform is loaded properly."""
2020-01-02 23:02:59 +00:00
await setup_axis_integration(hass)
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1
2020-10-22 07:29:53 +00:00
entity_id = f"{CAMERA_DOMAIN}.{NAME}"
cam = hass.states.get(entity_id)
assert cam.state == STATE_IDLE
2020-01-02 23:02:59 +00:00
assert cam.name == NAME
2020-10-22 07:29:53 +00:00
camera_entity = camera._get_camera_from_entity_id(hass, entity_id)
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"
)
async def test_camera_with_stream_profile(hass):
"""Test that Axis camera entity is using the correct path with stream profike."""
with patch.dict(ENTRY_OPTIONS, {CONF_STREAM_PROFILE: "profile_1"}):
await setup_axis_integration(hass)
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 1
2020-10-22 07:29:53 +00:00
entity_id = f"{CAMERA_DOMAIN}.{NAME}"
cam = hass.states.get(entity_id)
assert cam.state == STATE_IDLE
assert cam.name == NAME
2020-10-22 07:29:53 +00:00
camera_entity = camera._get_camera_from_entity_id(hass, entity_id)
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?streamprofile=profile_1"
)
assert (
await camera_entity.stream_source()
== "rtsp://root:pass@1.2.3.4/axis-media/media.amp?videocodec=h264&streamprofile=profile_1"
)
async def test_camera_disabled(hass):
"""Test that Axis camera platform is loaded properly but does not create camera entity."""
2023-01-02 17:14:14 +00:00
with patch("axis.vapix.vapix.Params.image_format", new=None):
await setup_axis_integration(hass)
assert len(hass.states.async_entity_ids(CAMERA_DOMAIN)) == 0