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 parent
16a947aa5f
commit
53844488d8
13 files changed
+430
-900
No files matched your search
@@ -1,72 +1,48 @@
|
||||
"""The tests for the Rfxtrx cover platform."""
|
||||
from unittest.mock import call
|
||||
|
||||
from homeassistant.components import rfxtrx as rfxtrx_core
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import _signal_event
|
||||
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
|
||||
async def test_valid_config(hass, rfxtrx):
|
||||
"""Test configuration."""
|
||||
with assert_setup_component(1):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
{
|
||||
"cover": {
|
||||
"platform": "rfxtrx",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {
|
||||
"name": "Test",
|
||||
rfxtrx_core.ATTR_FIRE_EVENT: True,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_default_config(hass, rfxtrx):
|
||||
"""Test with 0 cover."""
|
||||
assert await async_setup_component(
|
||||
hass, "cover", {"cover": {"platform": "rfxtrx", "devices": {}}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_one_cover(hass, rfxtrx):
|
||||
"""Test with 1 cover."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
"rfxtrx",
|
||||
{
|
||||
"cover": {
|
||||
"platform": "rfxtrx",
|
||||
"devices": {"0b1400cd0213c7f210010f51": {"name": "Test"}},
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {"0b1400cd0213c7f20d010f51": {}},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 1
|
||||
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||
assert state
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": "cover.test"}, blocking=True
|
||||
"cover",
|
||||
"open_cover",
|
||||
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": "cover.test"}, blocking=True
|
||||
"cover",
|
||||
"close_cover",
|
||||
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover", "stop_cover", {"entity_id": "cover.test"}, blocking=True
|
||||
"cover",
|
||||
"stop_cover",
|
||||
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert rfxtrx.transport.send.mock_calls == [
|
||||
@@ -80,74 +56,52 @@ async def test_several_covers(hass, rfxtrx):
|
||||
"""Test with 3 covers."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
"rfxtrx",
|
||||
{
|
||||
"cover": {
|
||||
"platform": "rfxtrx",
|
||||
"signal_repetitions": 3,
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230010f71": {"name": "Test"},
|
||||
"0b1100100118cdea02010f70": {"name": "Bath"},
|
||||
"0b1100101118cdea02010f70": {"name": "Living"},
|
||||
"0b1400cd0213c7f20d010f51": {},
|
||||
"0A1400ADF394AB010D0060": {},
|
||||
"09190000009ba8010100": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("cover.test")
|
||||
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||
assert state
|
||||
assert state.state == "closed"
|
||||
assert state.attributes.get("friendly_name") == "Test"
|
||||
assert state.attributes.get("friendly_name") == "LightwaveRF, Siemens 0213c7:242"
|
||||
|
||||
state = hass.states.get("cover.bath")
|
||||
state = hass.states.get("cover.lightwaverf_siemens_f394ab_1")
|
||||
assert state
|
||||
assert state.state == "closed"
|
||||
assert state.attributes.get("friendly_name") == "Bath"
|
||||
assert state.attributes.get("friendly_name") == "LightwaveRF, Siemens f394ab:1"
|
||||
|
||||
state = hass.states.get("cover.living")
|
||||
state = hass.states.get("cover.rollertrol_009ba8_1")
|
||||
assert state
|
||||
assert state.state == "closed"
|
||||
assert state.attributes.get("friendly_name") == "Living"
|
||||
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert state.attributes.get("friendly_name") == "RollerTrol 009ba8:1"
|
||||
|
||||
|
||||
async def test_discover_covers(hass, rfxtrx):
|
||||
"""Test with discovery of covers."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
{"cover": {"platform": "rfxtrx", "automatic_add": True, "devices": {}}},
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await _signal_event(hass, "0a140002f38cae010f0070")
|
||||
assert len(hass.states.async_all()) == 1
|
||||
state = hass.states.get("cover.lightwaverf_siemens_f38cae_1")
|
||||
assert state
|
||||
assert state.state == "open"
|
||||
|
||||
await _signal_event(hass, "0a1400adf394ab020e0060")
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
# Trying to add a sensor
|
||||
await _signal_event(hass, "0a52085e070100b31b0279")
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
# Trying to add a light
|
||||
await _signal_event(hass, "0b1100100118cdea02010f70")
|
||||
assert len(hass.states.async_all()) == 2
|
||||
|
||||
|
||||
async def test_discover_cover_noautoadd(hass, rfxtrx):
|
||||
"""Test with discovery of cover when auto add is False."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"cover",
|
||||
{"cover": {"platform": "rfxtrx", "automatic_add": False, "devices": {}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await _signal_event(hass, "0a1400adf394ab010d0060")
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
await _signal_event(hass, "0a1400adf394ab020e0060")
|
||||
assert len(hass.states.async_all()) == 0
|
||||
state = hass.states.get("cover.lightwaverf_siemens_f394ab_2")
|
||||
assert state
|
||||
assert state.state == "open"
|
||||
Reference in new issue
Block a user