Add lcn_codelock event and corresponding device trigger (#73022)

pull/74155/head
Andre Lengwenus 2022-06-28 23:01:18 +02:00 committed by GitHub
parent 9e61c7ec49
commit 389f1f4eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 3 deletions

View File

@ -191,7 +191,7 @@ def async_host_input_received(
def _async_fire_access_control_event(
hass: HomeAssistant, device: dr.DeviceEntry, address: AddressType, inp: InputType
) -> None:
"""Fire access control event (transponder, transmitter, fingerprint)."""
"""Fire access control event (transponder, transmitter, fingerprint, codelock)."""
event_data = {
"segment_id": address[0],
"module_id": address[1],

View File

@ -16,13 +16,14 @@ from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN, KEY_ACTIONS, SENDKEYS
TRIGGER_TYPES = {"transmitter", "transponder", "fingerprint", "send_keys"}
TRIGGER_TYPES = {"transmitter", "transponder", "fingerprint", "codelock", "send_keys"}
LCN_DEVICE_TRIGGER_BASE_SCHEMA = DEVICE_TRIGGER_BASE_SCHEMA.extend(
{vol.Required(CONF_TYPE): vol.In(TRIGGER_TYPES)}
)
ACCESS_CONTROL_SCHEMA = {vol.Optional("code"): vol.All(vol.Lower, cv.string)}
TRANSMITTER_SCHEMA = {
**ACCESS_CONTROL_SCHEMA,
vol.Optional("level"): cv.positive_int,
@ -45,6 +46,7 @@ TYPE_SCHEMAS = {
"transmitter": {"extra_fields": vol.Schema(TRANSMITTER_SCHEMA)},
"transponder": {"extra_fields": vol.Schema(ACCESS_CONTROL_SCHEMA)},
"fingerprint": {"extra_fields": vol.Schema(ACCESS_CONTROL_SCHEMA)},
"codelock": {"extra_fields": vol.Schema(ACCESS_CONTROL_SCHEMA)},
"send_keys": {"extra_fields": vol.Schema(SENDKEYS_SCHEMA)},
}

View File

@ -4,6 +4,7 @@
"transmitter": "transmitter code received",
"transponder": "transponder code received",
"fingerprint": "fingerprint code received",
"codelock": "code lock code received",
"send_keys": "send keys received"
}
}

View File

@ -1,6 +1,7 @@
{
"device_automation": {
"trigger_type": {
"codelock": "code lock code received",
"fingerprint": "fingerprint code received",
"send_keys": "send keys received",
"transmitter": "transmitter code received",

View File

@ -29,7 +29,13 @@ async def test_get_triggers_module_device(hass, entry, lcn_connection):
CONF_DEVICE_ID: device.id,
"metadata": {},
}
for trigger in ["transmitter", "transponder", "fingerprint", "send_keys"]
for trigger in [
"transmitter",
"transponder",
"fingerprint",
"codelock",
"send_keys",
]
]
triggers = await async_get_device_automations(
@ -147,6 +153,51 @@ async def test_if_fires_on_fingerprint_event(hass, calls, entry, lcn_connection)
}
async def test_if_fires_on_codelock_event(hass, calls, entry, lcn_connection):
"""Test for codelock event triggers firing."""
address = (0, 7, False)
device = get_device(hass, entry, address)
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {
CONF_PLATFORM: "device",
CONF_DOMAIN: DOMAIN,
CONF_DEVICE_ID: device.id,
CONF_TYPE: "codelock",
},
"action": {
"service": "test.automation",
"data_template": {
"test": "test_trigger_codelock",
"code": "{{ trigger.event.data.code }}",
},
},
},
]
},
)
inp = ModStatusAccessControl(
LcnAddr(*address),
periphery=AccessControlPeriphery.CODELOCK,
code="aabbcc",
)
await lcn_connection.async_process_input(inp)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data == {
"test": "test_trigger_codelock",
"code": "aabbcc",
}
async def test_if_fires_on_transmitter_event(hass, calls, entry, lcn_connection):
"""Test for transmitter event triggers firing."""
address = (0, 7, False)

View File

@ -42,6 +42,24 @@ async def test_fire_fingerprint_event(hass, lcn_connection):
assert events[0].data["code"] == "aabbcc"
async def test_fire_codelock_event(hass, lcn_connection):
"""Test the codelock event is fired."""
events = async_capture_events(hass, "lcn_codelock")
inp = ModStatusAccessControl(
LcnAddr(0, 7, False),
periphery=AccessControlPeriphery.CODELOCK,
code="aabbcc",
)
await lcn_connection.async_process_input(inp)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].event_type == "lcn_codelock"
assert events[0].data["code"] == "aabbcc"
async def test_fire_transmitter_event(hass, lcn_connection):
"""Test the transmitter event is fired."""
events = async_capture_events(hass, "lcn_transmitter")