2016-10-01 20:57:10 +00:00
|
|
|
"""The tests for the Rfxtrx component."""
|
2016-09-28 04:29:55 +00:00
|
|
|
|
2020-04-06 10:51:48 +00:00
|
|
|
from homeassistant.components import rfxtrx
|
2016-11-04 04:58:18 +00:00
|
|
|
from homeassistant.core import callback
|
2020-07-03 08:22:02 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from . import _signal_event
|
|
|
|
|
|
|
|
|
|
|
|
async def test_valid_config(hass):
|
|
|
|
"""Test configuration."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{
|
|
|
|
"rfxtrx": {
|
|
|
|
"device": "/dev/serial/by-id/usb"
|
|
|
|
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_valid_config2(hass):
|
|
|
|
"""Test configuration."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{
|
|
|
|
"rfxtrx": {
|
|
|
|
"device": "/dev/serial/by-id/usb"
|
|
|
|
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
"debug": True,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_invalid_config(hass):
|
|
|
|
"""Test configuration."""
|
|
|
|
assert not await async_setup_component(hass, "rfxtrx", {"rfxtrx": {}})
|
|
|
|
|
|
|
|
assert not await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{
|
|
|
|
"rfxtrx": {
|
|
|
|
"device": "/dev/serial/by-id/usb"
|
|
|
|
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
"invalid_key": True,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def test_fire_event(hass):
|
|
|
|
"""Test fire event."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{
|
|
|
|
"rfxtrx": {
|
|
|
|
"device": "/dev/serial/by-id/usb"
|
|
|
|
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
"automatic_add": True,
|
2020-07-13 00:57:19 +00:00
|
|
|
"devices": {
|
|
|
|
"0b1100cd0213c7f210010f51": {rfxtrx.CONF_FIRE_EVENT: True},
|
|
|
|
"0716000100900970": {rfxtrx.CONF_FIRE_EVENT: True},
|
|
|
|
},
|
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
|
|
|
|
|
|
|
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-13 00:57:19 +00:00
|
|
|
hass.bus.async_listen(rfxtrx.const.EVENT_RFXTRX_EVENT, record_event)
|
2020-07-05 20:41:11 +00:00
|
|
|
|
|
|
|
await _signal_event(hass, "0b1100cd0213c7f210010f51")
|
2020-07-13 00:57:19 +00:00
|
|
|
await _signal_event(hass, "0716000100900970")
|
2020-07-05 20:41:11 +00:00
|
|
|
|
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},
|
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",
|
|
|
|
"values": {"Sound": 9, "Battery numeric": 0, "Rssi numeric": 7},
|
|
|
|
},
|
|
|
|
]
|