hass-core/tests/components/rfxtrx/test_init.py
Joakim Plate 53844488d8
Switch rfxtrx to integration level config (#37742)
* Switch to integration level config

* Switch to per device config rather than per entity type

* All roller shutters should be added as covers

(there are non lighting types)

* Fixup tests that used invalid packets for platforms

* Avoid variable re-use

* Allow control events on sensors too

That way we get signal level sensors for these too

* Lint correction

* Don't filter sensors from config

Disable sensors from GUI if the entities are not wanted

* Correct usage of ATTR_ instead of CONF_

* Make sure the logging when a new entity is added includes the event
2020-07-12 22:03:22 +02:00

133 lines
3.3 KiB
Python

"""The tests for the Rfxtrx component."""
from homeassistant.components import rfxtrx
from homeassistant.core import callback
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,
"devices": {"0b1100cd0213c7f210010f51": {rfxtrx.ATTR_FIRE_EVENT: True}},
}
},
)
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)
state = hass.states.get("switch.ac_213c7f2_16")
assert state
assert state.state == "off"
await _signal_event(hass, "0b1100cd0213c7f210010f51")
state = hass.states.get("switch.ac_213c7f2_16")
assert state
assert state.state == "on"
assert any(
call.data == {"entity_id": "switch.ac_213c7f2_16", "state": "on"}
for call in calls
)
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,
"devices": {"0a520802060100ff0e0269": {rfxtrx.ATTR_FIRE_EVENT: True}},
}
},
)
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)
await _signal_event(hass, "0a520802060101ff0f0269")
assert len(calls) == 5
assert any(
call.data
== {"entity_id": "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature"}
for call in calls
)