diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index c3191ef9e3b..e5ffba44d40 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -66,6 +66,9 @@ def _valid_device(value, device_type): key = device.get('packetid') device.pop('packetid') + if not len(key) % 2 == 0: + key = '0' + key + if get_rfx_object(key) is None: raise vol.Invalid('Rfxtrx device {} is invalid: ' 'Invalid device id for {}'.format(key, value)) @@ -160,7 +163,11 @@ def get_rfx_object(packetid): """Return the RFXObject with the packetid.""" import RFXtrx as rfxtrxmod - binarypacket = bytearray.fromhex(packetid) + try: + binarypacket = bytearray.fromhex(packetid) + except ValueError: + return None + pkt = rfxtrxmod.lowlevel.parse(binarypacket) if pkt is None: return None diff --git a/tests/components/switch/test_rfxtrx.py b/tests/components/switch/test_rfxtrx.py index a73c843533c..8a36072304b 100644 --- a/tests/components/switch/test_rfxtrx.py +++ b/tests/components/switch/test_rfxtrx.py @@ -34,6 +34,17 @@ class TestSwitchRfxtrx(unittest.TestCase): rfxtrx_core.ATTR_FIREEVENT: True} }}})) + def test_valid_config_int_device_id(self): + """Test configuration.""" + self.assertTrue(_setup_component(self.hass, 'switch', { + 'switch': {'platform': 'rfxtrx', + 'automatic_add': True, + 'devices': + {'710000141010170': { + 'name': 'Test', + rfxtrx_core.ATTR_FIREEVENT: True} + }}})) + def test_invalid_config1(self): self.assertFalse(_setup_component(self.hass, 'switch', { 'switch': {'platform': 'rfxtrx',