diff --git a/homeassistant/components/lcn/__init__.py b/homeassistant/components/lcn/__init__.py index b0b231cb9e9..d1486fe0d32 100644 --- a/homeassistant/components/lcn/__init__.py +++ b/homeassistant/components/lcn/__init__.py @@ -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], diff --git a/homeassistant/components/lcn/device_trigger.py b/homeassistant/components/lcn/device_trigger.py index a6fc17759b8..8ae640cf6c2 100644 --- a/homeassistant/components/lcn/device_trigger.py +++ b/homeassistant/components/lcn/device_trigger.py @@ -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)}, } diff --git a/homeassistant/components/lcn/strings.json b/homeassistant/components/lcn/strings.json index 2ed8cb8d1c7..c0e46250c1e 100644 --- a/homeassistant/components/lcn/strings.json +++ b/homeassistant/components/lcn/strings.json @@ -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" } } diff --git a/homeassistant/components/lcn/translations/en.json b/homeassistant/components/lcn/translations/en.json index ad42b1ffc8f..37f092cbde7 100644 --- a/homeassistant/components/lcn/translations/en.json +++ b/homeassistant/components/lcn/translations/en.json @@ -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", diff --git a/tests/components/lcn/test_device_trigger.py b/tests/components/lcn/test_device_trigger.py index a52df987e5e..b908d21d5f5 100644 --- a/tests/components/lcn/test_device_trigger.py +++ b/tests/components/lcn/test_device_trigger.py @@ -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) diff --git a/tests/components/lcn/test_events.py b/tests/components/lcn/test_events.py index 38a685ad663..518af46b02a 100644 --- a/tests/components/lcn/test_events.py +++ b/tests/components/lcn/test_events.py @@ -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")