Skip to content

Commit

Permalink
Fix issue home-assistant#2290 for rfxtrx (home-assistant#2498)
Browse files Browse the repository at this point in the history
* Fix issue home-assistant#2290 for rfxtrx

* update tests for rfxtrx sensor

* Replace state_unkown with None in rfxtrx sensor

* Update test_rfxtrx.py
  • Loading branch information
Danielhiversen authored and balloob committed Jul 13, 2016
1 parent 497bc6a commit 16feb1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 63 deletions.
7 changes: 4 additions & 3 deletions homeassistant/components/sensor/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
data_types = [data_type]
break
for _data_type in data_types:
new_sensor = RfxtrxSensor(event, entity_info[ATTR_NAME],
new_sensor = RfxtrxSensor(None, entity_info[ATTR_NAME],
_data_type)
sensors.append(new_sensor)
sub_sensors[_data_type] = new_sensor
Expand Down Expand Up @@ -110,7 +110,7 @@ def __str__(self):
@property
def state(self):
"""Return the state of the sensor."""
if self.data_type:
if self.event:
return self.event.values[self.data_type]
return None

Expand All @@ -122,7 +122,8 @@ def name(self):
@property
def device_state_attributes(self):
"""Return the state attributes."""
return self.event.values
if self.event:
return self.event.values

@property
def unit_of_measurement(self):
Expand Down
67 changes: 7 additions & 60 deletions tests/components/sensor/test_rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ def test_old_config_sensor(self):
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)
self.assertEqual(None, entity.state)

def test_one_sensor(self):
"""Test with 1 sensor."""
Expand All @@ -64,12 +59,7 @@ def test_one_sensor(self):
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)
self.assertEqual(None, entity.state)

def test_one_sensor_no_datatype(self):
"""Test with 1 sensor."""
Expand All @@ -83,12 +73,7 @@ def test_one_sensor_no_datatype(self):
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)
self.assertEqual(None, entity.state)

def test_several_sensors(self):
"""Test with 3 sensors."""
Expand All @@ -112,35 +97,16 @@ def test_several_sensors(self):
_entity_temp = rfxtrx_core.RFX_DEVICES[id]['Temperature']
_entity_hum = rfxtrx_core.RFX_DEVICES[id]['Humidity']
self.assertEqual('%', _entity_hum.unit_of_measurement)
self.assertEqual(14, _entity_hum.state)
self.assertEqual({'Battery numeric': 9, 'Temperature': 25.5,
'Humidity': 14, 'Humidity status': 'normal',
'Humidity status numeric': 2,
'Rssi numeric': 6},
_entity_hum.device_state_attributes)
self.assertEqual('Bath', _entity_hum.__str__())

self.assertEqual(None, _entity_hum.state)
self.assertEqual(TEMP_CELSIUS,
_entity_temp.unit_of_measurement)
self.assertEqual(25.5, _entity_temp.state)
self.assertEqual({'Battery numeric': 9, 'Temperature': 25.5,
'Humidity': 14, 'Humidity status': 'normal',
'Humidity status numeric': 2,
'Rssi numeric': 6},
_entity_temp.device_state_attributes)
self.assertEqual('Bath', _entity_temp.__str__())
elif id == 'sensor_0502':
device_num = device_num + 1
entity = rfxtrx_core.RFX_DEVICES[id]['Temperature']

self.assertEqual(None, entity.state)
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)
self.assertEqual('Test', entity.__str__())

self.assertEqual(2, device_num)
Expand Down Expand Up @@ -252,35 +218,16 @@ def test_update_of_sensors(self):
_entity_temp = rfxtrx_core.RFX_DEVICES[id]['Temperature']
_entity_hum = rfxtrx_core.RFX_DEVICES[id]['Humidity']
self.assertEqual('%', _entity_hum.unit_of_measurement)
self.assertEqual(14, _entity_hum.state)
self.assertEqual({'Battery numeric': 9, 'Temperature': 25.5,
'Humidity': 14, 'Humidity status': 'normal',
'Humidity status numeric': 2,
'Rssi numeric': 6},
_entity_hum.device_state_attributes)
self.assertEqual('Bath', _entity_hum.__str__())

self.assertEqual(None, _entity_temp.state)
self.assertEqual(TEMP_CELSIUS,
_entity_temp.unit_of_measurement)
self.assertEqual(25.5, _entity_temp.state)
self.assertEqual({'Battery numeric': 9, 'Temperature': 25.5,
'Humidity': 14, 'Humidity status': 'normal',
'Humidity status numeric': 2,
'Rssi numeric': 6},
_entity_temp.device_state_attributes)
self.assertEqual('Bath', _entity_temp.__str__())
elif id == 'sensor_0502':
device_num = device_num + 1
entity = rfxtrx_core.RFX_DEVICES[id]['Temperature']

self.assertEqual(None, entity.state)
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)
self.assertEqual('Test', entity.__str__())

self.assertEqual(2, device_num)
Expand Down

0 comments on commit 16feb1c

Please sign in to comment.