2019-03-24 15:16:50 +00:00
|
|
|
"""Axis camera platform tests."""
|
|
|
|
|
|
|
|
from unittest.mock import Mock
|
|
|
|
|
|
|
|
from homeassistant import config_entries
|
|
|
|
from homeassistant.components import axis
|
|
|
|
import homeassistant.components.camera as camera
|
2019-12-08 14:44:04 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
ENTRY_CONFIG = {
|
|
|
|
axis.CONF_DEVICE: {
|
2019-07-31 19:25:30 +00:00
|
|
|
axis.config_flow.CONF_HOST: "1.2.3.4",
|
|
|
|
axis.config_flow.CONF_USERNAME: "user",
|
|
|
|
axis.config_flow.CONF_PASSWORD: "pass",
|
|
|
|
axis.config_flow.CONF_PORT: 80,
|
2019-03-24 15:16:50 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
axis.config_flow.CONF_MAC: "1234ABCD",
|
|
|
|
axis.config_flow.CONF_MODEL: "model",
|
|
|
|
axis.config_flow.CONF_NAME: "model 0",
|
2019-03-24 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ENTRY_OPTIONS = {
|
|
|
|
axis.CONF_CAMERA: False,
|
|
|
|
axis.CONF_EVENTS: True,
|
2019-07-31 19:25:30 +00:00
|
|
|
axis.CONF_TRIGGER_TIME: 0,
|
2019-03-24 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def setup_device(hass):
|
|
|
|
"""Load the Axis binary sensor platform."""
|
|
|
|
from axis import AxisDevice
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-03-24 15:16:50 +00:00
|
|
|
loop = Mock()
|
|
|
|
|
|
|
|
config_entry = config_entries.ConfigEntry(
|
2019-07-31 19:25:30 +00:00
|
|
|
1,
|
|
|
|
axis.DOMAIN,
|
|
|
|
"Mock Title",
|
|
|
|
ENTRY_CONFIG,
|
|
|
|
"test",
|
|
|
|
config_entries.CONN_CLASS_LOCAL_PUSH,
|
2019-08-18 04:34:11 +00:00
|
|
|
system_options={},
|
2019-07-31 19:25:30 +00:00
|
|
|
options=ENTRY_OPTIONS,
|
|
|
|
)
|
2019-03-24 15:16:50 +00:00
|
|
|
device = axis.AxisNetworkDevice(hass, config_entry)
|
2019-03-29 14:20:12 +00:00
|
|
|
device.api = AxisDevice(loop=loop, **config_entry.data[axis.CONF_DEVICE])
|
2019-03-24 15:16:50 +00:00
|
|
|
hass.data[axis.DOMAIN] = {device.serial: device}
|
2019-03-29 14:20:12 +00:00
|
|
|
device.api.enable_events(event_callback=device.async_event_callback)
|
2019-03-24 15:16:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setup(config_entry, "camera")
|
2019-03-24 15:16:50 +00:00
|
|
|
# To flush out the service call to update the group
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return device
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
hass, camera.DOMAIN, {"camera": {"platform": axis.DOMAIN}}
|
|
|
|
)
|
|
|
|
is True
|
|
|
|
)
|
2019-03-24 15:16:50 +00:00
|
|
|
|
|
|
|
assert axis.DOMAIN not in hass.data
|
|
|
|
|
|
|
|
|
|
|
|
async def test_camera(hass):
|
|
|
|
"""Test that Axis camera platform is loaded properly."""
|
|
|
|
await setup_device(hass)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 1
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
cam = hass.states.get("camera.model_0")
|
|
|
|
assert cam.state == "idle"
|
|
|
|
assert cam.name == "model 0"
|