Example #1
0
async def test_fire_sendkeys_event(hass, lcn_connection):
    """Test the send_keys event is fired."""
    events = async_capture_events(hass, "lcn_send_keys")

    inp = ModSendKeysHost(
        LcnAddr(0, 7, False),
        actions=[
            SendKeyCommand.HIT, SendKeyCommand.MAKE, SendKeyCommand.DONTSEND
        ],
        keys=[True, True, False, False, False, False, False, False],
    )

    await lcn_connection.async_process_input(inp)
    await hass.async_block_till_done()

    assert len(events) == 4
    assert events[0].event_type == "lcn_send_keys"
    assert events[0].data["key"] == "a1"
    assert events[0].data["action"] == "hit"
    assert events[1].event_type == "lcn_send_keys"
    assert events[1].data["key"] == "a2"
    assert events[1].data["action"] == "hit"
    assert events[2].event_type == "lcn_send_keys"
    assert events[2].data["key"] == "b1"
    assert events[2].data["action"] == "make"
    assert events[3].event_type == "lcn_send_keys"
    assert events[3].data["key"] == "b2"
    assert events[3].data["action"] == "make"
Example #2
0
async def test_if_fires_on_send_keys_event(hass, calls, entry):
    """Test for send_keys event triggers firing."""
    await init_integration(hass, entry)
    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: "send_keys",
                    },
                    "action": {
                        "service": "test.automation",
                        "data_template": {
                            "test": "test_trigger_send_keys",
                            "key": "{{ trigger.event.data.key }}",
                            "action": "{{ trigger.event.data.action }}",
                        },
                    },
                },
            ]
        },
    )

    inp = ModSendKeysHost(
        LcnAddr(*address),
        actions=[
            SendKeyCommand.HIT, SendKeyCommand.DONTSEND,
            SendKeyCommand.DONTSEND
        ],
        keys=[True, False, False, False, False, False, False, False],
    )

    lcn_connection = MockPchkConnectionManager.return_value
    await lcn_connection.async_process_input(inp)
    await hass.async_block_till_done()

    assert len(calls) == 1
    assert calls[0].data == {
        "test": "test_trigger_send_keys",
        "key": "a1",
        "action": "hit",
    }