Use fixtures in deCONZ alarm control panel tests (#120967)
parent
f1d6ad9073
commit
31ed32da6c
|
@ -1,12 +1,14 @@
|
||||||
"""deCONZ alarm control panel platform tests."""
|
"""deCONZ alarm control panel platform tests."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from collections.abc import Callable
|
||||||
|
|
||||||
from pydeconz.models.sensor.ancillary_control import AncillaryControlPanel
|
from pydeconz.models.sensor.ancillary_control import AncillaryControlPanel
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.alarm_control_panel import (
|
from homeassistant.components.alarm_control_panel import (
|
||||||
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
|
DOMAIN as ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_CODE,
|
ATTR_CODE,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
@ -26,29 +28,13 @@ from homeassistant.const import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .test_gateway import (
|
|
||||||
DECONZ_WEB_REQUEST,
|
|
||||||
mock_deconz_put_request,
|
|
||||||
setup_deconz_integration,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||||
|
|
||||||
|
|
||||||
async def test_no_sensors(
|
@pytest.mark.parametrize(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
"alarm_system_payload",
|
||||||
) -> None:
|
[
|
||||||
"""Test that no sensors in deconz results in no climate entities."""
|
{
|
||||||
await setup_deconz_integration(hass, aioclient_mock)
|
|
||||||
assert len(hass.states.async_all()) == 0
|
|
||||||
|
|
||||||
|
|
||||||
async def test_alarm_control_panel(
|
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, mock_deconz_websocket
|
|
||||||
) -> None:
|
|
||||||
"""Test successful creation of alarm control panel entities."""
|
|
||||||
data = {
|
|
||||||
"alarmsystems": {
|
|
||||||
"0": {
|
"0": {
|
||||||
"name": "default",
|
"name": "default",
|
||||||
"config": {
|
"config": {
|
||||||
|
@ -75,8 +61,13 @@ async def test_alarm_control_panel(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"sensors": {
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"sensor_payload",
|
||||||
|
[
|
||||||
|
{
|
||||||
"0": {
|
"0": {
|
||||||
"config": {
|
"config": {
|
||||||
"battery": 95,
|
"battery": 95,
|
||||||
|
@ -103,11 +94,17 @@ async def test_alarm_control_panel(
|
||||||
"type": "ZHAAncillaryControl",
|
"type": "ZHAAncillaryControl",
|
||||||
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
],
|
||||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
)
|
||||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
async def test_alarm_control_panel(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
config_entry_setup: ConfigEntry,
|
||||||
|
mock_put_request: Callable[[str, str], AiohttpClientMocker],
|
||||||
|
mock_deconz_websocket,
|
||||||
|
) -> None:
|
||||||
|
"""Test successful creation of alarm control panel entities."""
|
||||||
assert len(hass.states.async_all()) == 4
|
assert len(hass.states.async_all()) == 4
|
||||||
assert hass.states.get("alarm_control_panel.keypad").state == STATE_UNKNOWN
|
assert hass.states.get("alarm_control_panel.keypad").state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
@ -240,9 +237,7 @@ async def test_alarm_control_panel(
|
||||||
|
|
||||||
# Service set alarm to away mode
|
# Service set alarm to away mode
|
||||||
|
|
||||||
mock_deconz_put_request(
|
aioclient_mock = mock_put_request("/alarmsystems/0/arm_away")
|
||||||
aioclient_mock, config_entry.data, "/alarmsystems/0/arm_away"
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
ALARM_CONTROL_PANEL_DOMAIN,
|
ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
|
@ -254,9 +249,7 @@ async def test_alarm_control_panel(
|
||||||
|
|
||||||
# Service set alarm to home mode
|
# Service set alarm to home mode
|
||||||
|
|
||||||
mock_deconz_put_request(
|
aioclient_mock = mock_put_request("/alarmsystems/0/arm_stay")
|
||||||
aioclient_mock, config_entry.data, "/alarmsystems/0/arm_stay"
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
ALARM_CONTROL_PANEL_DOMAIN,
|
ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
|
@ -268,9 +261,7 @@ async def test_alarm_control_panel(
|
||||||
|
|
||||||
# Service set alarm to night mode
|
# Service set alarm to night mode
|
||||||
|
|
||||||
mock_deconz_put_request(
|
aioclient_mock = mock_put_request("/alarmsystems/0/arm_night")
|
||||||
aioclient_mock, config_entry.data, "/alarmsystems/0/arm_night"
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
ALARM_CONTROL_PANEL_DOMAIN,
|
ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
|
@ -282,7 +273,7 @@ async def test_alarm_control_panel(
|
||||||
|
|
||||||
# Service set alarm to disarmed
|
# Service set alarm to disarmed
|
||||||
|
|
||||||
mock_deconz_put_request(aioclient_mock, config_entry.data, "/alarmsystems/0/disarm")
|
aioclient_mock = mock_put_request("/alarmsystems/0/disarm")
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
ALARM_CONTROL_PANEL_DOMAIN,
|
ALARM_CONTROL_PANEL_DOMAIN,
|
||||||
|
@ -292,13 +283,13 @@ async def test_alarm_control_panel(
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[4][2] == {"code0": "4567"}
|
assert aioclient_mock.mock_calls[4][2] == {"code0": "4567"}
|
||||||
|
|
||||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
await hass.config_entries.async_unload(config_entry_setup.entry_id)
|
||||||
|
|
||||||
states = hass.states.async_all()
|
states = hass.states.async_all()
|
||||||
assert len(states) == 4
|
assert len(states) == 4
|
||||||
for state in states:
|
for state in states:
|
||||||
assert state.state == STATE_UNAVAILABLE
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(config_entry_setup.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
Loading…
Reference in New Issue