mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Improve Axis tests (#42183)
This commit is contained in:
@@ -4,6 +4,13 @@ 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.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .test_device import (
|
||||
@@ -53,7 +60,8 @@ async def test_no_switches(hass):
|
||||
|
||||
async def test_switches_with_port_cgi(hass):
|
||||
"""Test that switches are loaded properly using port.cgi."""
|
||||
device = await setup_axis_integration(hass)
|
||||
config_entry = await setup_axis_integration(hass)
|
||||
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
||||
|
||||
device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()}
|
||||
device.api.vapix.ports["0"].name = "Doorbell"
|
||||
@@ -67,26 +75,28 @@ async def test_switches_with_port_cgi(hass):
|
||||
|
||||
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"
|
||||
relay_1 = hass.states.get(f"{SWITCH_DOMAIN}.{NAME}_relay_1")
|
||||
assert relay_1.state == STATE_ON
|
||||
assert relay_1.name == f"{NAME} Relay 1"
|
||||
|
||||
entity_id = f"{SWITCH_DOMAIN}.{NAME}_doorbell"
|
||||
|
||||
relay_0 = hass.states.get(entity_id)
|
||||
assert relay_0.state == STATE_OFF
|
||||
assert relay_0.name == f"{NAME} Doorbell"
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
"turn_on",
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
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"},
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].open.assert_called_once()
|
||||
@@ -98,7 +108,8 @@ async def test_switches_with_port_management(hass):
|
||||
api_discovery["data"]["apiList"].append(API_DISCOVERY_PORT_MANAGEMENT)
|
||||
|
||||
with patch.dict(API_DISCOVERY_RESPONSE, api_discovery):
|
||||
device = await setup_axis_integration(hass)
|
||||
config_entry = await setup_axis_integration(hass)
|
||||
device = hass.data[AXIS_DOMAIN][config_entry.unique_id]
|
||||
|
||||
device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()}
|
||||
device.api.vapix.ports["0"].name = "Doorbell"
|
||||
@@ -112,26 +123,28 @@ async def test_switches_with_port_management(hass):
|
||||
|
||||
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"
|
||||
relay_1 = hass.states.get(f"{SWITCH_DOMAIN}.{NAME}_relay_1")
|
||||
assert relay_1.state == STATE_ON
|
||||
assert relay_1.name == f"{NAME} Relay 1"
|
||||
|
||||
entity_id = f"{SWITCH_DOMAIN}.{NAME}_doorbell"
|
||||
|
||||
relay_0 = hass.states.get(entity_id)
|
||||
assert relay_0.state == STATE_OFF
|
||||
assert relay_0.name == f"{NAME} Doorbell"
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
"turn_on",
|
||||
{"entity_id": f"switch.{NAME}_doorbell"},
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
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"},
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
device.api.vapix.ports["0"].open.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user