Revert zoneminder config flow (#41395)
This commit is contained in:
1 parent
088fb7eff3
commit
f4991794d4
22 files changed
+124
-1243
No files matched your search
@@ -1 +0,0 @@
|
||||
"""Tests for the zoneminder component."""
|
||||
@@ -1,65 +0,0 @@
|
||||
"""Binary sensor tests."""
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant.components.zoneminder import const
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test setup of binary sensor entities."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.is_available = True
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
unique_id="host1",
|
||||
data={
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await async_process_ha_core_config(hass, {})
|
||||
await async_setup_component(hass, HASS_DOMAIN, {})
|
||||
await async_setup_component(hass, const.DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "binary_sensor.host1"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("binary_sensor.host1").state == "on"
|
||||
|
||||
zm_client.is_available = False
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "binary_sensor.host1"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("binary_sensor.host1").state == "off"
|
||||
@@ -1,89 +0,0 @@
|
||||
"""Binary sensor tests."""
|
||||
from zoneminder.monitor import Monitor
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant.components.zoneminder import const
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test setup of camera entities."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
monitor1 = MagicMock(spec=Monitor)
|
||||
monitor1.name = "monitor1"
|
||||
monitor1.mjpeg_image_url = "mjpeg_image_url1"
|
||||
monitor1.still_image_url = "still_image_url1"
|
||||
monitor1.is_recording = True
|
||||
monitor1.is_available = True
|
||||
|
||||
monitor2 = MagicMock(spec=Monitor)
|
||||
monitor2.name = "monitor2"
|
||||
monitor2.mjpeg_image_url = "mjpeg_image_url2"
|
||||
monitor2.still_image_url = "still_image_url2"
|
||||
monitor2.is_recording = False
|
||||
monitor2.is_available = False
|
||||
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_monitors.return_value = [monitor1, monitor2]
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
unique_id="host1",
|
||||
data={
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
await async_process_ha_core_config(hass, {})
|
||||
await async_setup_component(hass, HASS_DOMAIN, {})
|
||||
await async_setup_component(hass, const.DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "camera.monitor1"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "camera.monitor2"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("camera.monitor1").state == "recording"
|
||||
assert hass.states.get("camera.monitor2").state == "unavailable"
|
||||
|
||||
monitor1.is_recording = False
|
||||
monitor2.is_recording = True
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "camera.monitor1"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "camera.monitor2"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("camera.monitor1").state == "idle"
|
||||
assert hass.states.get("camera.monitor2").state == "unavailable"
|
||||
@@ -1,119 +0,0 @@
|
||||
"""Config flow tests."""
|
||||
import requests
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.zoneminder import ClientAvailabilityResult, const
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_SOURCE,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
|
||||
|
||||
async def test_import(hass: HomeAssistant) -> None:
|
||||
"""Test import from configuration yaml."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
conf_data = {
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
}
|
||||
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
zm_client.login.return_value = False
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=conf_data,
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "auth_fail"
|
||||
|
||||
zm_client.login.return_value = True
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=conf_data,
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["data"] == {
|
||||
**conf_data,
|
||||
CONF_SOURCE: config_entries.SOURCE_IMPORT,
|
||||
}
|
||||
|
||||
|
||||
async def test_user(hass: HomeAssistant) -> None:
|
||||
"""Test user initiated creation."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
conf_data = {
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "form"
|
||||
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
zm_client.login.side_effect = requests.exceptions.ConnectionError()
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
conf_data,
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {
|
||||
"base": ClientAvailabilityResult.ERROR_CONNECTION_ERROR.value
|
||||
}
|
||||
|
||||
zm_client.login.side_effect = None
|
||||
zm_client.login.return_value = False
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
conf_data,
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {
|
||||
"base": ClientAvailabilityResult.ERROR_AUTH_FAIL.value
|
||||
}
|
||||
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
conf_data,
|
||||
)
|
||||
assert result
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["data"] == conf_data
|
||||
@@ -1,122 +0,0 @@
|
||||
"""Tests for init functions."""
|
||||
from datetime import timedelta
|
||||
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.zoneminder import const
|
||||
from homeassistant.components.zoneminder.common import is_client_in_data
|
||||
from homeassistant.config_entries import (
|
||||
ENTRY_STATE_LOADED,
|
||||
ENTRY_STATE_NOT_LOADED,
|
||||
ENTRY_STATE_SETUP_RETRY,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ID,
|
||||
ATTR_NAME,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_SOURCE,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_no_yaml_config(hass: HomeAssistant) -> None:
|
||||
"""Test empty yaml config."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_monitors.return_value = []
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
hass_config = {const.DOMAIN: []}
|
||||
await async_setup_component(hass, const.DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
assert not hass.services.has_service(const.DOMAIN, const.SERVICE_SET_RUN_STATE)
|
||||
|
||||
|
||||
async def test_yaml_config_import(hass: HomeAssistant) -> None:
|
||||
"""Test yaml config import."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_monitors.return_value = []
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
hass_config = {const.DOMAIN: [{CONF_HOST: "host1"}]}
|
||||
await async_setup_component(hass, const.DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.services.has_service(const.DOMAIN, const.SERVICE_SET_RUN_STATE)
|
||||
|
||||
|
||||
async def test_load_call_service_and_unload(hass: HomeAssistant) -> None:
|
||||
"""Test config entry load/unload and calling of service."""
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.side_effect = [True, True, False, True]
|
||||
zm_client.get_monitors.return_value = []
|
||||
zm_client.is_available.return_value = True
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
await hass.config_entries.flow.async_init(
|
||||
const.DOMAIN,
|
||||
context={CONF_SOURCE: config_entries.SOURCE_USER},
|
||||
data={
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config_entry = next(iter(hass.config_entries.async_entries(const.DOMAIN)), None)
|
||||
assert config_entry
|
||||
|
||||
assert config_entry.state == ENTRY_STATE_SETUP_RETRY
|
||||
assert not is_client_in_data(hass, "host1")
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state == ENTRY_STATE_LOADED
|
||||
assert is_client_in_data(hass, "host1")
|
||||
|
||||
assert hass.services.has_service(const.DOMAIN, const.SERVICE_SET_RUN_STATE)
|
||||
|
||||
await hass.services.async_call(
|
||||
const.DOMAIN,
|
||||
const.SERVICE_SET_RUN_STATE,
|
||||
{ATTR_ID: "host1", ATTR_NAME: "away"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
zm_client.set_active_state.assert_called_with("away")
|
||||
|
||||
await config_entry.async_unload(hass)
|
||||
await hass.async_block_till_done()
|
||||
assert config_entry.state == ENTRY_STATE_NOT_LOADED
|
||||
assert not is_client_in_data(hass, "host1")
|
||||
assert not hass.services.has_service(const.DOMAIN, const.SERVICE_SET_RUN_STATE)
|
||||
@@ -1,167 +0,0 @@
|
||||
"""Binary sensor tests."""
|
||||
from zoneminder.monitor import Monitor, MonitorState, TimePeriod
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.zoneminder import const
|
||||
from homeassistant.components.zoneminder.sensor import CONF_INCLUDE_ARCHIVED
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_PLATFORM,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test setup of sensor entities."""
|
||||
|
||||
def _get_events(monitor_id: int, time_period: TimePeriod, include_archived: bool):
|
||||
enum_list = [name for name in dir(TimePeriod) if not name.startswith("_")]
|
||||
tp_index = enum_list.index(time_period.name)
|
||||
return (100 * monitor_id) + (tp_index * 10) + include_archived
|
||||
|
||||
def _monitor1_get_events(time_period: TimePeriod, include_archived: bool):
|
||||
return _get_events(1, time_period, include_archived)
|
||||
|
||||
def _monitor2_get_events(time_period: TimePeriod, include_archived: bool):
|
||||
return _get_events(2, time_period, include_archived)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
monitor1 = MagicMock(spec=Monitor)
|
||||
monitor1.name = "monitor1"
|
||||
monitor1.mjpeg_image_url = "mjpeg_image_url1"
|
||||
monitor1.still_image_url = "still_image_url1"
|
||||
monitor1.is_recording = True
|
||||
monitor1.is_available = True
|
||||
monitor1.function = MonitorState.MONITOR
|
||||
monitor1.get_events.side_effect = _monitor1_get_events
|
||||
|
||||
monitor2 = MagicMock(spec=Monitor)
|
||||
monitor2.name = "monitor2"
|
||||
monitor2.mjpeg_image_url = "mjpeg_image_url2"
|
||||
monitor2.still_image_url = "still_image_url2"
|
||||
monitor2.is_recording = False
|
||||
monitor2.is_available = False
|
||||
monitor2.function = MonitorState.MODECT
|
||||
monitor2.get_events.side_effect = _monitor2_get_events
|
||||
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_monitors.return_value = [monitor1, monitor2]
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
unique_id="host1",
|
||||
data={
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
hass_config = {
|
||||
HASS_DOMAIN: {},
|
||||
SENSOR_DOMAIN: [
|
||||
{
|
||||
CONF_PLATFORM: const.DOMAIN,
|
||||
CONF_INCLUDE_ARCHIVED: True,
|
||||
CONF_MONITORED_CONDITIONS: ["all", "day"],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
await async_process_ha_core_config(hass, hass_config[HASS_DOMAIN])
|
||||
await async_setup_component(hass, HASS_DOMAIN, hass_config)
|
||||
await async_setup_component(hass, SENSOR_DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
await async_setup_component(hass, const.DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor1_status"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor1_events"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN,
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: "sensor.monitor1_events_last_day"},
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor2_status"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor2_events"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN,
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: "sensor.monitor2_events_last_day"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (
|
||||
hass.states.get("sensor.monitor1_status").state
|
||||
== MonitorState.MONITOR.value
|
||||
)
|
||||
assert hass.states.get("sensor.monitor1_events").state == "101"
|
||||
assert hass.states.get("sensor.monitor1_events_last_day").state == "111"
|
||||
assert hass.states.get("sensor.monitor2_status").state == "unavailable"
|
||||
assert hass.states.get("sensor.monitor2_events").state == "201"
|
||||
assert hass.states.get("sensor.monitor2_events_last_day").state == "211"
|
||||
|
||||
monitor1.function = MonitorState.NONE
|
||||
monitor2.function = MonitorState.NODECT
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor1_status"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor1_events"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN,
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: "sensor.monitor1_events_last_day"},
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor2_status"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "sensor.monitor2_events"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN,
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: "sensor.monitor2_events_last_day"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert (
|
||||
hass.states.get("sensor.monitor1_status").state == MonitorState.NONE.value
|
||||
)
|
||||
assert hass.states.get("sensor.monitor1_events").state == "101"
|
||||
assert hass.states.get("sensor.monitor1_events_last_day").state == "111"
|
||||
assert hass.states.get("sensor.monitor2_status").state == "unavailable"
|
||||
assert hass.states.get("sensor.monitor2_events").state == "201"
|
||||
assert hass.states.get("sensor.monitor2_events_last_day").state == "211"
|
||||
@@ -1,126 +0,0 @@
|
||||
"""Binary sensor tests."""
|
||||
from zoneminder.monitor import Monitor, MonitorState
|
||||
from zoneminder.zm import ZoneMinder
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.components.zoneminder import const
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_COMMAND_OFF,
|
||||
CONF_COMMAND_ON,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PATH,
|
||||
CONF_PLATFORM,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HASS_DOMAIN, HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import MagicMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass: HomeAssistant) -> None:
|
||||
"""Test setup of sensor entities."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.zoneminder.common.ZoneMinder", autospec=ZoneMinder
|
||||
) as zoneminder_mock:
|
||||
monitor1 = MagicMock(spec=Monitor)
|
||||
monitor1.name = "monitor1"
|
||||
monitor1.mjpeg_image_url = "mjpeg_image_url1"
|
||||
monitor1.still_image_url = "still_image_url1"
|
||||
monitor1.is_recording = True
|
||||
monitor1.is_available = True
|
||||
monitor1.function = MonitorState.MONITOR
|
||||
|
||||
monitor2 = MagicMock(spec=Monitor)
|
||||
monitor2.name = "monitor2"
|
||||
monitor2.mjpeg_image_url = "mjpeg_image_url2"
|
||||
monitor2.still_image_url = "still_image_url2"
|
||||
monitor2.is_recording = False
|
||||
monitor2.is_available = False
|
||||
monitor2.function = MonitorState.MODECT
|
||||
|
||||
zm_client: ZoneMinder = MagicMock(spec=ZoneMinder)
|
||||
zm_client.get_zms_url.return_value = "http://host1/path_zms1"
|
||||
zm_client.login.return_value = True
|
||||
zm_client.get_monitors.return_value = [monitor1, monitor2]
|
||||
|
||||
zoneminder_mock.return_value = zm_client
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=const.DOMAIN,
|
||||
unique_id="host1",
|
||||
data={
|
||||
CONF_HOST: "host1",
|
||||
CONF_USERNAME: "username1",
|
||||
CONF_PASSWORD: "password1",
|
||||
CONF_PATH: "path1",
|
||||
const.CONF_PATH_ZMS: "path_zms1",
|
||||
CONF_SSL: False,
|
||||
CONF_VERIFY_SSL: True,
|
||||
},
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
hass_config = {
|
||||
HASS_DOMAIN: {},
|
||||
SWITCH_DOMAIN: [
|
||||
{
|
||||
CONF_PLATFORM: const.DOMAIN,
|
||||
CONF_COMMAND_ON: MonitorState.MONITOR.value,
|
||||
CONF_COMMAND_OFF: MonitorState.MODECT.value,
|
||||
},
|
||||
{
|
||||
CONF_PLATFORM: const.DOMAIN,
|
||||
CONF_COMMAND_ON: MonitorState.MODECT.value,
|
||||
CONF_COMMAND_OFF: MonitorState.MONITOR.value,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
await async_process_ha_core_config(hass, hass_config[HASS_DOMAIN])
|
||||
await async_setup_component(hass, HASS_DOMAIN, hass_config)
|
||||
await async_setup_component(hass, SWITCH_DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
await async_setup_component(hass, const.DOMAIN, hass_config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN, "turn_on", {ATTR_ENTITY_ID: "switch.monitor1_state"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN, "turn_off", {ATTR_ENTITY_ID: "switch.monitor1_state_2"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("switch.monitor1_state").state == STATE_ON
|
||||
assert hass.states.get("switch.monitor1_state_2").state == STATE_OFF
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN, "turn_off", {ATTR_ENTITY_ID: "switch.monitor1_state"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN, "turn_on", {ATTR_ENTITY_ID: "switch.monitor1_state_2"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("switch.monitor1_state").state == STATE_OFF
|
||||
assert hass.states.get("switch.monitor1_state_2").state == STATE_ON
|
||||
|
||||
monitor1.function = MonitorState.NONE
|
||||
monitor2.function = MonitorState.NODECT
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "switch.monitor1_state"}
|
||||
)
|
||||
await hass.services.async_call(
|
||||
HASS_DOMAIN, "update_entity", {ATTR_ENTITY_ID: "switch.monitor1_state_2"}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("switch.monitor1_state").state == STATE_OFF
|
||||
assert hass.states.get("switch.monitor1_state_2").state == STATE_OFF
|
||||
Reference in new issue
Block a user