Fix bug in rfxtrx for int device id (#2497)

pull/2501/head
Daniel Høyer Iversen 2016-07-12 10:45:22 +02:00 committed by Paulus Schoutsen
parent 6d60287455
commit 09a4336bc5
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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',