Improve Axis integration (#36205)
* Improve configuration * Read new properties for basic device information Improve tests by mocking less improving stability of tests * Clean up in device tests * Support new port management api * Improve initializing data * Bump dependency to v28
This commit is contained in:
1 parent
6ed68d8ced
commit
01d9366299
10 files changed
+215
-152
No files matched your search
@@ -1,14 +1,19 @@
|
||||
"""Axis switch platform tests."""
|
||||
|
||||
from axis.port_cgi import ACTION_HIGH, ACTION_LOW
|
||||
from copy import deepcopy
|
||||
|
||||
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_device import NAME, setup_axis_integration
|
||||
from .test_device import (
|
||||
API_DISCOVERY_PORT_MANAGEMENT,
|
||||
API_DISCOVERY_RESPONSE,
|
||||
NAME,
|
||||
setup_axis_integration,
|
||||
)
|
||||
|
||||
from tests.async_mock import Mock, call as mock_call
|
||||
from tests.async_mock import Mock, patch
|
||||
|
||||
EVENTS = [
|
||||
{
|
||||
@@ -46,8 +51,8 @@ async def test_no_switches(hass):
|
||||
assert not hass.states.async_entity_ids(SWITCH_DOMAIN)
|
||||
|
||||
|
||||
async def test_switches(hass):
|
||||
"""Test that switches are loaded properly."""
|
||||
async def test_switches_with_port_cgi(hass):
|
||||
"""Test that switches are loaded properly using port.cgi."""
|
||||
device = await setup_axis_integration(hass)
|
||||
|
||||
device.api.vapix.ports = {"0": Mock(), "1": Mock()}
|
||||
@@ -68,14 +73,13 @@ async def test_switches(hass):
|
||||
assert relay_1.state == "on"
|
||||
assert relay_1.name == f"{NAME} Relay 1"
|
||||
|
||||
device.api.vapix.ports["0"].action = Mock()
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
"turn_on",
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].close.assert_called_once()
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
@@ -83,8 +87,47 @@ async def test_switches(hass):
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].open.assert_called_once()
|
||||
|
||||
assert device.api.vapix.ports["0"].action.call_args_list == [
|
||||
mock_call(ACTION_HIGH),
|
||||
mock_call(ACTION_LOW),
|
||||
]
|
||||
|
||||
async def test_switches_with_port_management(hass):
|
||||
"""Test that switches are loaded properly using port management."""
|
||||
api_discovery = deepcopy(API_DISCOVERY_RESPONSE)
|
||||
api_discovery["data"]["apiList"].append(API_DISCOVERY_PORT_MANAGEMENT)
|
||||
|
||||
with patch.dict(API_DISCOVERY_RESPONSE, api_discovery):
|
||||
device = await setup_axis_integration(hass)
|
||||
|
||||
device.api.vapix.ports = {"0": Mock(), "1": Mock()}
|
||||
device.api.vapix.ports["0"].name = "Doorbell"
|
||||
device.api.vapix.ports["1"].name = ""
|
||||
|
||||
for event in EVENTS:
|
||||
device.api.event.process_event(event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 2
|
||||
|
||||
relay_0 = hass.states.get(f"switch.{NAME}_doorbell")
|
||||
assert relay_0.state == "off"
|
||||
assert relay_0.name == f"{NAME} Doorbell"
|
||||
|
||||
relay_1 = hass.states.get(f"switch.{NAME}_relay_1")
|
||||
assert relay_1.state == "on"
|
||||
assert relay_1.name == f"{NAME} Relay 1"
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
"turn_on",
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].close.assert_called_once()
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
"turn_off",
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].open.assert_called_once()
|
||||
Reference in new issue
Block a user