2016-10-01 20:57:10 +00:00
|
|
|
"""The tests for the Rfxtrx component."""
|
2016-09-28 04:29:55 +00:00
|
|
|
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import call
|
|
|
|
|
2020-10-01 06:55:57 +00:00
|
|
|
from homeassistant.components.rfxtrx import DOMAIN
|
2020-07-21 22:24:26 +00:00
|
|
|
from homeassistant.components.rfxtrx.const import EVENT_RFXTRX_EVENT
|
2016-11-04 04:58:18 +00:00
|
|
|
from homeassistant.core import callback
|
2021-03-09 13:28:32 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-10-01 06:55:57 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
2020-07-13 14:54:52 +00:00
|
|
|
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-07-21 22:24:26 +00:00
|
|
|
async def test_fire_event(hass, rfxtrx):
|
2020-07-03 08:22:02 +00:00
|
|
|
"""Test fire event."""
|
2020-10-01 06:55:57 +00:00
|
|
|
entry_data = create_rfx_test_cfg(
|
|
|
|
device="/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
automatic_add=True,
|
|
|
|
devices={
|
|
|
|
"0b1100cd0213c7f210010f51": {"fire_event": True},
|
|
|
|
"0716000100900970": {"fire_event": True},
|
2020-07-03 08:22:02 +00:00
|
|
|
},
|
|
|
|
)
|
2020-10-01 06:55:57 +00:00
|
|
|
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
|
|
|
|
|
|
|
mock_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
2020-07-03 08:22:02 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-07-13 00:57:19 +00:00
|
|
|
await hass.async_start()
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2021-03-09 13:28:32 +00:00
|
|
|
device_registry: dr.DeviceRegistry = dr.async_get(hass)
|
2021-01-04 14:31:10 +00:00
|
|
|
|
2020-07-03 08:22:02 +00:00
|
|
|
calls = []
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def record_event(event):
|
|
|
|
"""Add recorded event to set."""
|
2020-07-13 00:57:19 +00:00
|
|
|
assert event.event_type == "rfxtrx_event"
|
|
|
|
calls.append(event.data)
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-07-21 22:24:26 +00:00
|
|
|
hass.bus.async_listen(EVENT_RFXTRX_EVENT, record_event)
|
2020-07-05 20:41:11 +00:00
|
|
|
|
2020-07-21 22:24:26 +00:00
|
|
|
await rfxtrx.signal("0b1100cd0213c7f210010f51")
|
|
|
|
await rfxtrx.signal("0716000100900970")
|
2020-07-05 20:41:11 +00:00
|
|
|
|
2021-01-04 14:31:10 +00:00
|
|
|
device_id_1 = device_registry.async_get_device(
|
2021-01-07 12:49:45 +00:00
|
|
|
identifiers={("rfxtrx", "11", "0", "213c7f2:16")}
|
2021-01-04 14:31:10 +00:00
|
|
|
)
|
|
|
|
assert device_id_1
|
|
|
|
|
|
|
|
device_id_2 = device_registry.async_get_device(
|
2021-01-07 12:49:45 +00:00
|
|
|
identifiers={("rfxtrx", "16", "0", "00:90")}
|
2021-01-04 14:31:10 +00:00
|
|
|
)
|
|
|
|
assert device_id_2
|
|
|
|
|
2020-07-13 00:57:19 +00:00
|
|
|
assert calls == [
|
2020-07-03 08:22:02 +00:00
|
|
|
{
|
2020-07-13 00:57:19 +00:00
|
|
|
"packet_type": 17,
|
|
|
|
"sub_type": 0,
|
|
|
|
"type_string": "AC",
|
|
|
|
"id_string": "213c7f2:16",
|
|
|
|
"data": "0b1100cd0213c7f210010f51",
|
|
|
|
"values": {"Command": "On", "Rssi numeric": 5},
|
2021-01-04 14:31:10 +00:00
|
|
|
"device_id": device_id_1.id,
|
2020-07-03 08:22:02 +00:00
|
|
|
},
|
2020-07-13 00:57:19 +00:00
|
|
|
{
|
|
|
|
"packet_type": 22,
|
|
|
|
"sub_type": 0,
|
|
|
|
"type_string": "Byron SX",
|
|
|
|
"id_string": "00:90",
|
|
|
|
"data": "0716000100900970",
|
2021-06-16 01:34:05 +00:00
|
|
|
"values": {"Command": "Sound 9", "Rssi numeric": 7, "Sound": 9},
|
2021-01-04 14:31:10 +00:00
|
|
|
"device_id": device_id_2.id,
|
2020-07-13 00:57:19 +00:00
|
|
|
},
|
|
|
|
]
|
2020-07-13 14:54:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_send(hass, rfxtrx):
|
|
|
|
"""Test configuration."""
|
2020-10-01 06:55:57 +00:00
|
|
|
entry_data = create_rfx_test_cfg(device="/dev/null", devices={})
|
|
|
|
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
|
|
|
|
|
|
|
mock_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
2020-07-13 14:54:52 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"rfxtrx", "send", {"event": "0a520802060101ff0f0269"}, blocking=True
|
|
|
|
)
|
|
|
|
|
|
|
|
assert rfxtrx.transport.send.mock_calls == [
|
|
|
|
call(bytearray(b"\x0a\x52\x08\x02\x06\x01\x01\xff\x0f\x02\x69"))
|
|
|
|
]
|