Config validation for MQTT binary_sensor platform.
This commit is contained in:
parent
0bd4e15fcb
commit
287f0f4f68
2 changed files with 41 additions and 28 deletions
|
@ -1,6 +1,7 @@
|
|||
"""The tests for the MQTT binary sensor platform."""
|
||||
import unittest
|
||||
|
||||
from homeassistant.bootstrap import _setup_component
|
||||
import homeassistant.components.binary_sensor as binary_sensor
|
||||
from tests.common import mock_mqtt_component, fire_mqtt_message
|
||||
from homeassistant.const import (STATE_OFF, STATE_ON)
|
||||
|
@ -22,15 +23,16 @@ class TestSensorMQTT(unittest.TestCase):
|
|||
|
||||
def test_setting_sensor_value_via_mqtt_message(self):
|
||||
"""Test the setting of the value via MQTT."""
|
||||
self.assertTrue(binary_sensor.setup(self.hass, {
|
||||
'binary_sensor': {
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||
binary_sensor.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'test-topic',
|
||||
'payload_on': 'ON',
|
||||
'payload_off': 'OFF',
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
state = self.hass.states.get('binary_sensor.test')
|
||||
self.assertEqual(STATE_OFF, state.state)
|
||||
|
@ -47,28 +49,30 @@ class TestSensorMQTT(unittest.TestCase):
|
|||
|
||||
def test_valid_sensor_class(self):
|
||||
"""Test the setting of a valid sensor class."""
|
||||
self.assertTrue(binary_sensor.setup(self.hass, {
|
||||
'binary_sensor': {
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||
binary_sensor.DOMAIN: {
|
||||
'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': {
|
||||
self.hass.config.components = ['mqtt']
|
||||
assert _setup_component(self.hass, binary_sensor.DOMAIN, {
|
||||
binary_sensor.DOMAIN: {
|
||||
'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'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue