Fix bug in rfxtrx for int device id (#2497)
parent
6d60287455
commit
09a4336bc5
|
@ -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
|
||||
|
||||
try:
|
||||
binarypacket = bytearray.fromhex(packetid)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
pkt = rfxtrxmod.lowlevel.parse(binarypacket)
|
||||
if pkt is None:
|
||||
return None
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue