Refactor rfxtrx code
This commit is contained in:
1 parent
55b51cb3fa
commit
2ca1f7542f
6 files changed
+125
-130
No files matched your search
@@ -194,7 +194,7 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['0e611622']
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 0e611622 : 0b11009e00e6116202020070: on>',
|
||||
self.assertEqual('<Entity 0b11009e00e6116202020070: on>',
|
||||
entity.__str__())
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0b11009e00e6116201010070')
|
||||
@@ -210,7 +210,7 @@ class TestLightRfxtrx(unittest.TestCase):
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['118cdea2']
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 118cdea2 : 0b1100120118cdea02020070: on>',
|
||||
self.assertEqual('<Entity 0b1100120118cdea02020070: on>',
|
||||
entity.__str__())
|
||||
|
||||
# trying to add a sensor
|
||||
|
||||
@@ -71,6 +71,25 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
'Humidity status numeric': 2},
|
||||
entity.device_state_attributes)
|
||||
|
||||
def test_one_sensor_no_datatype(self):
|
||||
"""Test with 1 sensor."""
|
||||
self.assertTrue(_setup_component(self.hass, 'sensor', {
|
||||
'sensor': {'platform': 'rfxtrx',
|
||||
'devices':
|
||||
{'0a52080705020095220269': {
|
||||
'name': 'Test'}}}}))
|
||||
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
entity = rfxtrx_core.RFX_DEVICES['sensor_0502']['Temperature']
|
||||
self.assertEqual('Test', entity.name)
|
||||
self.assertEqual(TEMP_CELSIUS, entity.unit_of_measurement)
|
||||
self.assertEqual(14.9, entity.state)
|
||||
self.assertEqual({'Humidity status': 'normal', 'Temperature': 14.9,
|
||||
'Rssi numeric': 6, 'Humidity': 34,
|
||||
'Battery numeric': 9,
|
||||
'Humidity status numeric': 2},
|
||||
entity.device_state_attributes)
|
||||
|
||||
def test_several_sensors(self):
|
||||
"""Test with 3 sensors."""
|
||||
self.assertTrue(_setup_component(self.hass, 'sensor', {
|
||||
@@ -145,7 +164,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
'Battery numeric': 9,
|
||||
'Humidity status numeric': 2},
|
||||
entity.device_state_attributes)
|
||||
self.assertEqual('sensor_0701 : 0a520801070100b81b0279',
|
||||
self.assertEqual('0a520801070100b81b0279',
|
||||
entity.__str__())
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
@@ -162,7 +181,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
'Battery numeric': 9,
|
||||
'Humidity status numeric': 2},
|
||||
entity.device_state_attributes)
|
||||
self.assertEqual('sensor_0502 : 0a52080405020095240279',
|
||||
self.assertEqual('0a52080405020095240279',
|
||||
entity.__str__())
|
||||
|
||||
event = rfxtrx_core.get_rfx_object('0a52085e070100b31b0279')
|
||||
@@ -176,7 +195,7 @@ class TestSensorRfxtrx(unittest.TestCase):
|
||||
'Battery numeric': 9,
|
||||
'Humidity status numeric': 2},
|
||||
entity.device_state_attributes)
|
||||
self.assertEqual('sensor_0701 : 0a520801070100b81b0279',
|
||||
self.assertEqual('0a520801070100b81b0279',
|
||||
entity.__str__())
|
||||
|
||||
# trying to add a switch
|
||||
|
||||
@@ -190,7 +190,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['118cdea2']
|
||||
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 118cdea2 : 0b1100100118cdea01010f70: on>',
|
||||
self.assertEqual('<Entity 0b1100100118cdea01010f70: on>',
|
||||
entity.__str__())
|
||||
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
@@ -203,7 +203,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
||||
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
|
||||
entity = rfxtrx_core.RFX_DEVICES['118cdeb2']
|
||||
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
|
||||
self.assertEqual('<Entity 118cdeb2 : 0b1100120118cdea02000070: on>',
|
||||
self.assertEqual('<Entity 0b1100120118cdea02000070: on>',
|
||||
entity.__str__())
|
||||
|
||||
# Trying to add a sensor
|
||||
|
||||
@@ -37,10 +37,10 @@ class TestRFXTRX(unittest.TestCase):
|
||||
'automatic_add': True,
|
||||
'devices': {}}}))
|
||||
|
||||
while len(rfxtrx.RFX_DEVICES) < 2:
|
||||
while len(rfxtrx.RFX_DEVICES) < 1:
|
||||
time.sleep(0.1)
|
||||
|
||||
self.assertEqual(len(rfxtrx.RFXOBJECT.sensors()), 2)
|
||||
self.assertEqual(len(rfxtrx.RFXOBJECT.sensors()), 1)
|
||||
|
||||
def test_valid_config(self):
|
||||
"""Test configuration."""
|
||||
|
||||
Reference in new issue
Block a user