mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +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:
@@ -3,127 +3,79 @@ from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
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,
|
||||
"light",
|
||||
{
|
||||
"light": {
|
||||
"platform": "rfxtrx",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {
|
||||
"name": "Test",
|
||||
rfxtrx_core.ATTR_FIRE_EVENT: True,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{
|
||||
"light": {
|
||||
"platform": "rfxtrx",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {
|
||||
"name": "Test",
|
||||
"signal_repetitions": 3,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def test_default_config(hass, rfxtrx):
|
||||
"""Test with 0 switches."""
|
||||
with assert_setup_component(1):
|
||||
await async_setup_component(
|
||||
hass, "light", {"light": {"platform": "rfxtrx", "devices": {}}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_one_light(hass, rfxtrx):
|
||||
"""Test with 1 light."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
"rfxtrx",
|
||||
{
|
||||
"light": {
|
||||
"platform": "rfxtrx",
|
||||
"devices": {"0b1100cd0213c7f210010f51": {"name": "Test"}},
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {"0b1100cd0213c7f210020f51": {}},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("friendly_name") == "Test"
|
||||
assert state.attributes.get("friendly_name") == "AC 213c7f2:16"
|
||||
|
||||
await hass.services.async_call(
|
||||
"light", "turn_on", {"entity_id": "light.test"}, blocking=True
|
||||
"light", "turn_on", {"entity_id": "light.ac_213c7f2_16"}, blocking=True
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
await hass.services.async_call(
|
||||
"light", "turn_off", {"entity_id": "light.test"}, blocking=True
|
||||
"light", "turn_off", {"entity_id": "light.ac_213c7f2_16"}, blocking=True
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("brightness") is None
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.test", "brightness": 100},
|
||||
{"entity_id": "light.ac_213c7f2_16", "brightness": 100},
|
||||
blocking=True,
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("brightness") == 100
|
||||
|
||||
await hass.services.async_call(
|
||||
"light", "turn_on", {"entity_id": "light.test", "brightness": 10}, blocking=True
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.ac_213c7f2_16", "brightness": 10},
|
||||
blocking=True,
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("brightness") == 10
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.test", "brightness": 255},
|
||||
{"entity_id": "light.ac_213c7f2_16", "brightness": 255},
|
||||
blocking=True,
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("brightness") == 255
|
||||
|
||||
await hass.services.async_call(
|
||||
"light", "turn_off", {"entity_id": "light.test"}, blocking=True
|
||||
"light", "turn_off", {"entity_id": "light.ac_213c7f2_16"}, blocking=True
|
||||
)
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("brightness") is None
|
||||
|
||||
@@ -139,61 +91,59 @@ async def test_one_light(hass, rfxtrx):
|
||||
|
||||
async def test_several_lights(hass, rfxtrx):
|
||||
"""Test with 3 lights."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
"rfxtrx",
|
||||
{
|
||||
"light": {
|
||||
"platform": "rfxtrx",
|
||||
"signal_repetitions": 3,
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230010f71": {"name": "Test"},
|
||||
"0b1100100118cdea02010f70": {"name": "Bath"},
|
||||
"0b1100101118cdea02010f70": {"name": "Living"},
|
||||
"0b1100cd0213c7f230020f71": {},
|
||||
"0b1100100118cdea02020f70": {},
|
||||
"0b1100101118cdea02050f70": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 3
|
||||
|
||||
state = hass.states.get("light.test")
|
||||
state = hass.states.get("light.ac_213c7f2_48")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("friendly_name") == "Test"
|
||||
assert state.attributes.get("friendly_name") == "AC 213c7f2:48"
|
||||
|
||||
state = hass.states.get("light.bath")
|
||||
state = hass.states.get("light.ac_118cdea_2")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("friendly_name") == "Bath"
|
||||
assert state.attributes.get("friendly_name") == "AC 118cdea:2"
|
||||
|
||||
state = hass.states.get("light.living")
|
||||
state = hass.states.get("light.ac_1118cdea_2")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes.get("friendly_name") == "Living"
|
||||
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert state.attributes.get("friendly_name") == "AC 1118cdea:2"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("repetitions", [1, 3])
|
||||
async def test_repetitions(hass, rfxtrx, repetitions):
|
||||
"""Test signal repetitions."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
"rfxtrx",
|
||||
{
|
||||
"light": {
|
||||
"platform": "rfxtrx",
|
||||
"signal_repetitions": repetitions,
|
||||
"devices": {"0b1100cd0213c7f230010f71": {"name": "Test"}},
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230020f71": {"signal_repetitions": repetitions}
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
"light", "turn_on", {"entity_id": "light.test"}, blocking=True
|
||||
"light", "turn_on", {"entity_id": "light.ac_213c7f2_48"}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
@@ -202,40 +152,21 @@ async def test_repetitions(hass, rfxtrx, repetitions):
|
||||
|
||||
async def test_discover_light(hass, rfxtrx):
|
||||
"""Test with discovery of lights."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"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, "0b11009e00e6116202020070")
|
||||
state = hass.states.get("light.0b11009e00e6116202020070")
|
||||
state = hass.states.get("light.ac_0e61162_2")
|
||||
assert state
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("friendly_name") == "0b11009e00e6116202020070"
|
||||
assert state.attributes.get("friendly_name") == "AC 0e61162:2"
|
||||
|
||||
await _signal_event(hass, "0b1100120118cdea02020070")
|
||||
state = hass.states.get("light.0b1100120118cdea02020070")
|
||||
state = hass.states.get("light.ac_118cdea_2")
|
||||
assert state
|
||||
assert state.state == "on"
|
||||
assert state.attributes.get("friendly_name") == "0b1100120118cdea02020070"
|
||||
|
||||
|
||||
async def test_discover_light_noautoadd(hass, rfxtrx):
|
||||
"""Test with discover of light when auto add is False."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"light",
|
||||
{"light": {"platform": "rfxtrx", "automatic_add": False, "devices": {}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await _signal_event(hass, "0b1100120118cdea02020070")
|
||||
assert hass.states.async_all() == []
|
||||
|
||||
await _signal_event(hass, "0b1100120118cdea02010070")
|
||||
assert hass.states.async_all() == []
|
||||
|
||||
await _signal_event(hass, "0b1100120118cdea02020070")
|
||||
assert hass.states.async_all() == []
|
||||
assert state.attributes.get("friendly_name") == "AC 118cdea:2"
|
||||
|
||||
Reference in New Issue
Block a user