mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
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
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
"""The tests for the Rfxtrx component."""
|
||||
# pylint: disable=protected-access
|
||||
import asyncio
|
||||
|
||||
from async_timeout import timeout
|
||||
|
||||
from homeassistant.components import rfxtrx
|
||||
from homeassistant.core import callback
|
||||
@@ -10,37 +6,6 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
|
||||
async def test_default_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,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
with assert_setup_component(1, "sensor"):
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
{"sensor": {"platform": "rfxtrx", "automatic_add": True, "devices": {}}},
|
||||
)
|
||||
|
||||
# Dummy startup is slow
|
||||
async with timeout(10):
|
||||
while len(hass.data[rfxtrx.DATA_RFXOBJECT].sensors()) < 2:
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
assert len(hass.data[rfxtrx.DATA_RFXOBJECT].sensors()) == 2
|
||||
|
||||
|
||||
async def test_valid_config(hass):
|
||||
"""Test configuration."""
|
||||
@@ -100,23 +65,8 @@ async def test_fire_event(hass):
|
||||
"device": "/dev/serial/by-id/usb"
|
||||
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
"dummy": True,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"switch",
|
||||
{
|
||||
"switch": {
|
||||
"platform": "rfxtrx",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {
|
||||
"name": "Test",
|
||||
rfxtrx.ATTR_FIRE_EVENT: True,
|
||||
}
|
||||
},
|
||||
"devices": {"0b1100cd0213c7f210010f51": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -131,18 +81,20 @@ async def test_fire_event(hass):
|
||||
|
||||
hass.bus.async_listen(rfxtrx.EVENT_BUTTON_PRESSED, record_event)
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
state = hass.states.get("switch.ac_213c7f2_16")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
|
||||
await _signal_event(hass, "0b1100cd0213c7f210010f51")
|
||||
|
||||
state = hass.states.get("switch.test")
|
||||
state = hass.states.get("switch.ac_213c7f2_16")
|
||||
assert state
|
||||
assert state.state == "on"
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == {"entity_id": "switch.test", "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):
|
||||
@@ -155,26 +107,12 @@ async def test_fire_event_sensor(hass):
|
||||
"device": "/dev/serial/by-id/usb"
|
||||
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
"dummy": True,
|
||||
"automatic_add": True,
|
||||
"devices": {"0a520802060100ff0e0269": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "rfxtrx",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0a520802060100ff0e0269": {
|
||||
"name": "Test",
|
||||
rfxtrx.ATTR_FIRE_EVENT: True,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
calls = []
|
||||
@@ -188,4 +126,8 @@ async def test_fire_event_sensor(hass):
|
||||
|
||||
await _signal_event(hass, "0a520802060101ff0f0269")
|
||||
assert len(calls) == 5
|
||||
assert any(call.data == {"entity_id": "sensor.test_temperature"} for call in calls)
|
||||
assert any(
|
||||
call.data
|
||||
== {"entity_id": "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature"}
|
||||
for call in calls
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user