diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 947a945eee7..a7f7425fb81 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -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 for event_code, event_config in data[CONF_DEVICES].items(): event = get_rfx_object(event_code) + if event is None: + continue device_id = get_device_id( event.device, data_bits=event_config.get(CONF_DATA_BITS) ) @@ -229,6 +231,8 @@ def _get_device_lookup(devices): lookup = dict() for event_code, event_config in devices.items(): event = get_rfx_object(event_code) + if event is None: + continue device_id = get_device_id( event.device, data_bits=event_config.get(CONF_DATA_BITS) ) diff --git a/tests/components/rfxtrx/test_binary_sensor.py b/tests/components/rfxtrx/test_binary_sensor.py index 11efcfb6510..ee757192aaf 100644 --- a/tests/components/rfxtrx/test_binary_sensor.py +++ b/tests/components/rfxtrx/test_binary_sensor.py @@ -69,6 +69,35 @@ async def test_one_pt2262(hass, rfxtrx): 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( "state,event", [["on", "0b1100cd0213c7f230010f71"], ["off", "0b1100cd0213c7f230000f71"]], @@ -262,3 +291,35 @@ async def test_light(hass, rfxtrx_automatic): await rfxtrx.signal(EVENT_LIGHT_DETECTOR_DARK) 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" diff --git a/tests/components/rfxtrx/test_cover.py b/tests/components/rfxtrx/test_cover.py index ce4838cebf1..05ce26ebc10 100644 --- a/tests/components/rfxtrx/test_cover.py +++ b/tests/components/rfxtrx/test_cover.py @@ -114,3 +114,26 @@ async def test_discover_covers(hass, rfxtrx_automatic): state = hass.states.get("cover.lightwaverf_siemens_f394ab_2") assert state 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" diff --git a/tests/components/rfxtrx/test_switch.py b/tests/components/rfxtrx/test_switch.py index 3256f303708..1fed6a65562 100644 --- a/tests/components/rfxtrx/test_switch.py +++ b/tests/components/rfxtrx/test_switch.py @@ -3,6 +3,7 @@ from unittest.mock import call import pytest +from homeassistant.components.rfxtrx import DOMAIN from homeassistant.core import State 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") assert state 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"