Increase test coverage for rfxtrx integration (#39340)
* Increase switch coverage * Increase binary sensor coverage * Final improvements * Remove debug statement * Adjust test duplicate cover * Remove None return test * Assert on length of conf_entries Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
parent
b315df2118
commit
5658a1efec
4 changed files with 110 additions and 0 deletions
|
@ -156,6 +156,8 @@ async def async_setup(hass, config):
|
||||||
# Read device_id from the event code add to the data that will end up in the ConfigEntry
|
# Read device_id from the event code add to the data that will end up in the ConfigEntry
|
||||||
for event_code, event_config in data[CONF_DEVICES].items():
|
for event_code, event_config in data[CONF_DEVICES].items():
|
||||||
event = get_rfx_object(event_code)
|
event = get_rfx_object(event_code)
|
||||||
|
if event is None:
|
||||||
|
continue
|
||||||
device_id = get_device_id(
|
device_id = get_device_id(
|
||||||
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
||||||
)
|
)
|
||||||
|
@ -229,6 +231,8 @@ def _get_device_lookup(devices):
|
||||||
lookup = dict()
|
lookup = dict()
|
||||||
for event_code, event_config in devices.items():
|
for event_code, event_config in devices.items():
|
||||||
event = get_rfx_object(event_code)
|
event = get_rfx_object(event_code)
|
||||||
|
if event is None:
|
||||||
|
continue
|
||||||
device_id = get_device_id(
|
device_id = get_device_id(
|
||||||
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
event.device, data_bits=event_config.get(CONF_DATA_BITS)
|
||||||
)
|
)
|
||||||
|
|
|
@ -69,6 +69,35 @@ async def test_one_pt2262(hass, rfxtrx):
|
||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_pt2262_unconfigured(hass, rfxtrx):
|
||||||
|
"""Test with discovery for PT2262."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"rfxtrx",
|
||||||
|
{
|
||||||
|
"rfxtrx": {
|
||||||
|
"device": "abcd",
|
||||||
|
"devices": {
|
||||||
|
"0913000022670e013970": {},
|
||||||
|
"09130000226707013970": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_start()
|
||||||
|
|
||||||
|
state = hass.states.get("binary_sensor.pt2262_22670e")
|
||||||
|
assert state
|
||||||
|
assert state.state == "off" # probably aught to be unknown
|
||||||
|
assert state.attributes.get("friendly_name") == "PT2262 22670e"
|
||||||
|
|
||||||
|
state = hass.states.get("binary_sensor.pt2262_226707")
|
||||||
|
assert state
|
||||||
|
assert state.state == "off" # probably aught to be unknown
|
||||||
|
assert state.attributes.get("friendly_name") == "PT2262 226707"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"state,event",
|
"state,event",
|
||||||
[["on", "0b1100cd0213c7f230010f71"], ["off", "0b1100cd0213c7f230000f71"]],
|
[["on", "0b1100cd0213c7f230010f71"], ["off", "0b1100cd0213c7f230000f71"]],
|
||||||
|
@ -262,3 +291,35 @@ async def test_light(hass, rfxtrx_automatic):
|
||||||
|
|
||||||
await rfxtrx.signal(EVENT_LIGHT_DETECTOR_DARK)
|
await rfxtrx.signal(EVENT_LIGHT_DETECTOR_DARK)
|
||||||
assert hass.states.get(entity_id).state == "off"
|
assert hass.states.get(entity_id).state == "off"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_pt2262_duplicate_id(hass, rfxtrx):
|
||||||
|
"""Test with 1 sensor."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"rfxtrx",
|
||||||
|
{
|
||||||
|
"rfxtrx": {
|
||||||
|
"device": "abcd",
|
||||||
|
"devices": {
|
||||||
|
"0913000022670e013970": {
|
||||||
|
"data_bits": 4,
|
||||||
|
"command_on": 0xE,
|
||||||
|
"command_off": 0x7,
|
||||||
|
},
|
||||||
|
"09130000226707013970": {
|
||||||
|
"data_bits": 4,
|
||||||
|
"command_on": 0xE,
|
||||||
|
"command_off": 0x7,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
await hass.async_start()
|
||||||
|
|
||||||
|
state = hass.states.get("binary_sensor.pt2262_22670e")
|
||||||
|
assert state
|
||||||
|
assert state.state == "off" # probably aught to be unknown
|
||||||
|
assert state.attributes.get("friendly_name") == "PT2262 22670e"
|
||||||
|
|
|
@ -114,3 +114,26 @@ async def test_discover_covers(hass, rfxtrx_automatic):
|
||||||
state = hass.states.get("cover.lightwaverf_siemens_f394ab_2")
|
state = hass.states.get("cover.lightwaverf_siemens_f394ab_2")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "open"
|
assert state.state == "open"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_duplicate_cover(hass, rfxtrx):
|
||||||
|
"""Test with 2 duplicate covers."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"rfxtrx",
|
||||||
|
{
|
||||||
|
"rfxtrx": {
|
||||||
|
"device": "abcd",
|
||||||
|
"devices": {
|
||||||
|
"0b1400cd0213c7f20d010f51": {},
|
||||||
|
"0b1400cd0213c7f20d010f50": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||||
|
assert state
|
||||||
|
assert state.state == "closed"
|
||||||
|
assert state.attributes.get("friendly_name") == "LightwaveRF, Siemens 0213c7:242"
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest.mock import call
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.rfxtrx import DOMAIN
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
@ -151,3 +152,24 @@ async def test_discover_rfy_sun_switch(hass, rfxtrx_automatic):
|
||||||
state = hass.states.get("switch.rfy_030101_1")
|
state = hass.states.get("switch.rfy_030101_1")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "on"
|
assert state.state == "on"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_unknown_event_code(hass, rfxtrx):
|
||||||
|
"""Test with 3 switches."""
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
"rfxtrx",
|
||||||
|
{
|
||||||
|
"rfxtrx": {
|
||||||
|
"device": "abcd",
|
||||||
|
"devices": {"1234567890": {}},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
conf_entries = hass.config_entries.async_entries(DOMAIN)
|
||||||
|
assert len(conf_entries) == 1
|
||||||
|
|
||||||
|
entry = conf_entries[0]
|
||||||
|
assert entry.state == "loaded"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue