2016-10-01 13:57:10 -07:00
|
|
|
"""The tests for the Rfxtrx component."""
|
2016-09-27 21:29:55 -07:00
|
|
|
|
2020-04-06 12:51:48 +02:00
|
|
|
from homeassistant.components import rfxtrx
|
2016-11-03 21:58:18 -07:00
|
|
|
from homeassistant.core import callback
|
2020-07-03 10:22:02 +02: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",
|
|
|
|
"dummy": True,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
"dummy": True,
|
|
|
|
"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",
|
|
|
|
"dummy": True,
|
|
|
|
"automatic_add": True,
|
2020-07-12 22:03:22 +02:00
|
|
|
"devices": {"0b1100cd0213c7f210010f51": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
2020-07-03 10:22:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
calls = []
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def record_event(event):
|
|
|
|
"""Add recorded event to set."""
|
|
|
|
calls.append(event)
|
|
|
|
|
|
|
|
hass.bus.async_listen(rfxtrx.EVENT_BUTTON_PRESSED, record_event)
|
|
|
|
|
2020-07-12 22:03:22 +02:00
|
|
|
state = hass.states.get("switch.ac_213c7f2_16")
|
2020-07-05 22:41:11 +02:00
|
|
|
assert state
|
|
|
|
assert state.state == "off"
|
|
|
|
|
|
|
|
await _signal_event(hass, "0b1100cd0213c7f210010f51")
|
|
|
|
|
2020-07-12 22:03:22 +02:00
|
|
|
state = hass.states.get("switch.ac_213c7f2_16")
|
2020-07-05 22:41:11 +02:00
|
|
|
assert state
|
|
|
|
assert state.state == "on"
|
|
|
|
|
2020-07-12 22:03:22 +02:00
|
|
|
assert any(
|
|
|
|
call.data == {"entity_id": "switch.ac_213c7f2_16", "state": "on"}
|
|
|
|
for call in calls
|
|
|
|
)
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_fire_event_sensor(hass):
|
|
|
|
"""Test fire event."""
|
|
|
|
await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{
|
|
|
|
"rfxtrx": {
|
|
|
|
"device": "/dev/serial/by-id/usb"
|
|
|
|
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
|
|
|
"dummy": True,
|
|
|
|
"automatic_add": True,
|
2020-07-12 22:03:22 +02:00
|
|
|
"devices": {"0a520802060100ff0e0269": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
2020-07-03 10:22:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2020-07-12 22:03:22 +02:00
|
|
|
|
2020-07-03 10:22:02 +02:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
calls = []
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def record_event(event):
|
|
|
|
"""Add recorded event to set."""
|
|
|
|
calls.append(event)
|
|
|
|
|
|
|
|
hass.bus.async_listen("signal_received", record_event)
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a520802060101ff0f0269")
|
2020-07-10 14:52:07 +02:00
|
|
|
assert len(calls) == 5
|
2020-07-12 22:03:22 +02:00
|
|
|
assert any(
|
|
|
|
call.data
|
|
|
|
== {"entity_id": "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature"}
|
|
|
|
for call in calls
|
|
|
|
)
|