Add sensor_class to MQTT binary sensor

This commit is contained in:
Fabian Affolter 2016-03-10 20:51:58 +01:00
parent f22a40c3e8
commit 4637a83c29
2 changed files with 45 additions and 4 deletions

View file

@ -44,3 +44,31 @@ class TestSensorMQTT(unittest.TestCase):
self.hass.pool.block_till_done()
state = self.hass.states.get('binary_sensor.test')
self.assertEqual(STATE_OFF, state.state)
def test_valid_sensor_class(self):
"""Test the setting of a valid sensor class."""
self.assertTrue(binary_sensor.setup(self.hass, {
'binary_sensor': {
'platform': 'mqtt',
'name': 'test',
'sensor_class': 'motion',
'state_topic': 'test-topic',
}
}))
state = self.hass.states.get('binary_sensor.test')
self.assertEqual('motion', state.attributes.get('sensor_class'))
def test_invalid_sensor_class(self):
"""Test the setting of an invalid sensor class."""
self.assertTrue(binary_sensor.setup(self.hass, {
'binary_sensor': {
'platform': 'mqtt',
'name': 'test',
'sensor_class': 'abc123',
'state_topic': 'test-topic',
}
}))
state = self.hass.states.get('binary_sensor.test')
self.assertIsNone(state.attributes.get('sensor_class'))