Пример #1
0
async def test_fire_transmitter_event(hass, entry):
    """Test the transmitter event is fired."""
    await init_integration(hass, entry)

    events = async_capture_events(hass, "lcn_transmitter")

    inp = ModStatusAccessControl(
        LcnAddr(0, 7, False),
        periphery=AccessControlPeriphery.TRANSMITTER,
        code="aabbcc",
        level=0,
        key=0,
        action=KeyAction.HIT,
    )

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

    assert len(events) == 1
    assert events[0].event_type == "lcn_transmitter"
    assert events[0].data["code"] == "aabbcc"
    assert events[0].data["level"] == 0
    assert events[0].data["key"] == 0
    assert events[0].data["action"] == "hit"
Пример #2
0
async def test_if_fires_on_transmitter_event(hass, calls, entry):
    """Test for transmitter 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: "transmitter",
                    },
                    "action": {
                        "service": "test.automation",
                        "data_template": {
                            "test": "test_trigger_transmitter",
                            "code": "{{ trigger.event.data.code }}",
                            "level": "{{ trigger.event.data.level }}",
                            "key": "{{ trigger.event.data.key }}",
                            "action": "{{ trigger.event.data.action }}",
                        },
                    },
                },
            ]
        },
    )

    inp = ModStatusAccessControl(
        LcnAddr(*address),
        periphery=AccessControlPeriphery.TRANSMITTER,
        code="aabbcc",
        level=0,
        key=0,
        action=KeyAction.HIT,
    )

    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_transmitter",
        "code": "aabbcc",
        "level": 0,
        "key": 0,
        "action": "hit",
    }
Пример #3
0
async def test_dont_fire_on_unknown_module(hass, lcn_connection):
    """Test for no event is fired if an input from an unknown module is received."""
    inp = ModStatusAccessControl(
        LcnAddr(0, 10, False),  # unknown module
        periphery=AccessControlPeriphery.FINGERPRINT,
        code="aabbcc",
    )

    events = async_capture_events(hass, "lcn_fingerprint")
    await lcn_connection.async_process_input(inp)
    await hass.async_block_till_done()
    assert len(events) == 0
Пример #4
0
async def test_fire_transponder_event(hass, lcn_connection):
    """Test the transponder event is fired."""
    events = async_capture_events(hass, "lcn_transponder")

    inp = ModStatusAccessControl(
        LcnAddr(0, 7, False),
        periphery=AccessControlPeriphery.TRANSPONDER,
        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_transponder"
    assert events[0].data["code"] == "aabbcc"
Пример #5
0
async def test_fire_fingerprint_event(hass, lcn_connection):
    """Test the fingerprint event is fired."""
    events = async_capture_events(hass, "lcn_fingerprint")

    inp = ModStatusAccessControl(
        LcnAddr(0, 7, False),
        periphery=AccessControlPeriphery.FINGERPRINT,
        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_fingerprint"
    assert events[0].data["code"] == "aabbcc"
Пример #6
0
async def test_dont_fire_on_unknown_module(hass, entry):
    """Test for no event is fired if an input from an unknown module is received."""
    await init_integration(hass, entry)

    inp = ModStatusAccessControl(
        LcnAddr(0, 10, False),  # unknown module
        periphery=AccessControlPeriphery.FINGERPRINT,
        code="aabbcc",
    )

    lcn_connection = MockPchkConnectionManager.return_value

    events = async_capture_events(hass, "lcn_transmitter")
    await lcn_connection.async_process_input(inp)
    await hass.async_block_till_done()
    assert len(events) == 0
async def test_if_fires_on_transponder_event(hass, calls, entry,
                                             lcn_connection):
    """Test for transponder 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: "transponder",
                    },
                    "action": {
                        "service": "test.automation",
                        "data_template": {
                            "test": "test_trigger_transponder",
                            "code": "{{ trigger.event.data.code }}",
                        },
                    },
                },
            ]
        },
    )

    inp = ModStatusAccessControl(
        LcnAddr(*address),
        periphery=AccessControlPeriphery.TRANSPONDER,
        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_transponder",
        "code": "aabbcc",
    }
Пример #8
0
async def test_fire_transmitter_event(hass, lcn_connection):
    """Test the transmitter event is fired."""
    events = async_capture_events(hass, LCN_TRANSMITTER)

    inp = ModStatusAccessControl(
        LcnAddr(0, 7, False),
        periphery=AccessControlPeriphery.TRANSMITTER,
        code="aabbcc",
        level=0,
        key=0,
        action=KeyAction.HIT,
    )

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

    assert len(events) == 1
    assert events[0].event_type == LCN_TRANSMITTER
    assert events[0].data["code"] == "aabbcc"
    assert events[0].data["level"] == 0
    assert events[0].data["key"] == 0
    assert events[0].data["action"] == "hit"