mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add alarm control panel support to deCONZ integration (#48736)
* Infrastructure in place * Base implementation * Add alarm event * Add custom services to alarm control panel * Add service descriptions * Increase test coverage * Simplified to one entity service with an options selector * Remove everything but the essentials * Add library with proper support * Fix stale comments
This commit is contained in:
@@ -3,8 +3,18 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.deconz.const import DOMAIN as DECONZ_DOMAIN
|
||||
from homeassistant.components.deconz.deconz_event import CONF_DECONZ_EVENT
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.components.deconz.deconz_event import (
|
||||
CONF_DECONZ_ALARM_EVENT,
|
||||
CONF_DECONZ_EVENT,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_CODE,
|
||||
CONF_DEVICE_ID,
|
||||
CONF_EVENT,
|
||||
CONF_ID,
|
||||
CONF_UNIQUE_ID,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.helpers.device_registry import async_entries_for_config_entry
|
||||
|
||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||
@@ -161,6 +171,20 @@ async def test_deconz_events(hass, aioclient_mock, mock_deconz_websocket):
|
||||
"device_id": device.id,
|
||||
}
|
||||
|
||||
# Unsupported event
|
||||
|
||||
event_changed_sensor = {
|
||||
"t": "event",
|
||||
"e": "changed",
|
||||
"r": "sensors",
|
||||
"id": "1",
|
||||
"name": "other name",
|
||||
}
|
||||
await mock_deconz_websocket(data=event_changed_sensor)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(captured_events) == 4
|
||||
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
states = hass.states.async_all()
|
||||
@@ -173,6 +197,100 @@ async def test_deconz_events(hass, aioclient_mock, mock_deconz_websocket):
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_deconz_alarm_events(hass, aioclient_mock, mock_deconz_websocket):
|
||||
"""Test successful creation of deconz alarm events."""
|
||||
data = {
|
||||
"sensors": {
|
||||
"1": {
|
||||
"config": {
|
||||
"armed": "disarmed",
|
||||
"enrolled": 0,
|
||||
"on": True,
|
||||
"panel": "disarmed",
|
||||
"pending": [],
|
||||
"reachable": True,
|
||||
},
|
||||
"ep": 1,
|
||||
"etag": "3c4008d74035dfaa1f0bb30d24468b12",
|
||||
"lastseen": "2021-04-02T13:07Z",
|
||||
"manufacturername": "Universal Electronics Inc",
|
||||
"modelid": "URC4450BC0-X-R",
|
||||
"name": "Keypad",
|
||||
"state": {
|
||||
"action": "armed_away,1111,55",
|
||||
"lastupdated": "2021-04-02T13:08:18.937",
|
||||
"lowbattery": False,
|
||||
"tampered": True,
|
||||
},
|
||||
"type": "ZHAAncillaryControl",
|
||||
"uniqueid": "00:00:00:00:00:00:00:01-01-0501",
|
||||
}
|
||||
}
|
||||
}
|
||||
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
# 1 alarm control device + 2 additional devices for deconz service and host
|
||||
assert (
|
||||
len(async_entries_for_config_entry(device_registry, config_entry.entry_id)) == 3
|
||||
)
|
||||
|
||||
captured_events = async_capture_events(hass, CONF_DECONZ_ALARM_EVENT)
|
||||
|
||||
# Armed away event
|
||||
|
||||
event_changed_sensor = {
|
||||
"t": "event",
|
||||
"e": "changed",
|
||||
"r": "sensors",
|
||||
"id": "1",
|
||||
"state": {"action": "armed_away,1234,1"},
|
||||
}
|
||||
await mock_deconz_websocket(data=event_changed_sensor)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
identifiers={(DECONZ_DOMAIN, "00:00:00:00:00:00:00:01")}
|
||||
)
|
||||
|
||||
assert len(captured_events) == 1
|
||||
assert captured_events[0].data == {
|
||||
CONF_ID: "keypad",
|
||||
CONF_UNIQUE_ID: "00:00:00:00:00:00:00:01",
|
||||
CONF_DEVICE_ID: device.id,
|
||||
CONF_EVENT: "armed_away",
|
||||
CONF_CODE: "1234",
|
||||
}
|
||||
|
||||
# Unsupported event
|
||||
|
||||
event_changed_sensor = {
|
||||
"t": "event",
|
||||
"e": "changed",
|
||||
"r": "sensors",
|
||||
"id": "1",
|
||||
"config": {"panel": "armed_away"},
|
||||
}
|
||||
await mock_deconz_websocket(data=event_changed_sensor)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(captured_events) == 1
|
||||
|
||||
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
states = hass.states.async_all()
|
||||
assert len(hass.states.async_all()) == 1
|
||||
for state in states:
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_deconz_events_bad_unique_id(hass, aioclient_mock, mock_deconz_websocket):
|
||||
"""Verify no devices are created if unique id is bad or missing."""
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user