mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
binary_sensor sensor_class to entity device_class (#5860)
* binary_sensor sensor_class to entity device_class * Linter fixes * Should be it
This commit is contained in:
committed by
Paulus Schoutsen
parent
67957cbfa8
commit
e877d572f5
@@ -23,13 +23,3 @@ class TestBinarySensor(unittest.TestCase):
|
||||
new=True):
|
||||
self.assertEqual(STATE_ON,
|
||||
binary_sensor.BinarySensorDevice().state)
|
||||
|
||||
def test_attributes(self):
|
||||
"""Test binary sensor attributes."""
|
||||
sensor = binary_sensor.BinarySensorDevice()
|
||||
self.assertEqual({}, sensor.state_attributes)
|
||||
with mock.patch('homeassistant.components.binary_sensor.'
|
||||
'BinarySensorDevice.sensor_class',
|
||||
new='motion'):
|
||||
self.assertEqual({'sensor_class': 'motion'},
|
||||
sensor.state_attributes)
|
||||
|
||||
@@ -47,32 +47,32 @@ class TestSensorMQTT(unittest.TestCase):
|
||||
state = self.hass.states.get('binary_sensor.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
||||
def test_valid_sensor_class(self):
|
||||
def test_valid_device_class(self):
|
||||
"""Test the setting of a valid sensor class."""
|
||||
self.hass.config.components = set(['mqtt'])
|
||||
assert setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||
binary_sensor.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'sensor_class': 'motion',
|
||||
'device_class': 'motion',
|
||||
'state_topic': 'test-topic',
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('binary_sensor.test')
|
||||
self.assertEqual('motion', state.attributes.get('sensor_class'))
|
||||
self.assertEqual('motion', state.attributes.get('device_class'))
|
||||
|
||||
def test_invalid_sensor_class(self):
|
||||
def test_invalid_device_class(self):
|
||||
"""Test the setting of an invalid sensor class."""
|
||||
self.hass.config.components = set(['mqtt'])
|
||||
assert setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||
binary_sensor.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'sensor_class': 'abc123',
|
||||
'device_class': 'abc123',
|
||||
'state_topic': 'test-topic',
|
||||
}
|
||||
})
|
||||
|
||||
state = self.hass.states.get('binary_sensor.test')
|
||||
self.assertIsNone(state.attributes.get('sensor_class'))
|
||||
self.assertIsNone(state)
|
||||
|
||||
@@ -36,7 +36,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
'test': {
|
||||
'friendly_name': 'virtual thingy',
|
||||
'value_template': '{{ foo }}',
|
||||
'sensor_class': 'motion',
|
||||
'device_class': 'motion',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -66,7 +66,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
}
|
||||
})
|
||||
|
||||
def test_setup_invalid_sensor_class(self):
|
||||
def test_setup_invalid_device_class(self):
|
||||
""""Test setup with invalid sensor class."""
|
||||
with assert_setup_component(0):
|
||||
assert bootstrap.setup_component(self.hass, 'binary_sensor', {
|
||||
@@ -75,7 +75,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
'sensors': {
|
||||
'test': {
|
||||
'value_template': '{{ foo }}',
|
||||
'sensor_class': 'foobarnotreal',
|
||||
'device_class': 'foobarnotreal',
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -89,7 +89,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
'platform': 'template',
|
||||
'sensors': {
|
||||
'test': {
|
||||
'sensor_class': 'motion',
|
||||
'device_class': 'motion',
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
template_hlpr.Template('{{ 1 > 1 }}', self.hass), MATCH_ALL
|
||||
).result()
|
||||
self.assertFalse(vs.should_poll)
|
||||
self.assertEqual('motion', vs.sensor_class)
|
||||
self.assertEqual('motion', vs.device_class)
|
||||
self.assertEqual('Parent', vs.name)
|
||||
|
||||
vs.update()
|
||||
|
||||
Reference in New Issue
Block a user