Config validation for MQTT sensor platform.

This commit is contained in:
Jan Harkes 2016-04-06 20:32:35 -04:00
parent 3383854506
commit eb3f812e38
2 changed files with 31 additions and 19 deletions

View file

@ -1,6 +1,7 @@
"""The tests for the MQTT sensor platform."""
import unittest
from homeassistant.bootstrap import _setup_component
import homeassistant.components.sensor as sensor
from tests.common import mock_mqtt_component, fire_mqtt_message
@ -21,14 +22,15 @@ class TestSensorMQTT(unittest.TestCase):
def test_setting_sensor_value_via_mqtt_message(self):
"""Test the setting of the value via MQTT."""
self.assertTrue(sensor.setup(self.hass, {
'sensor': {
self.hass.config.components = ['mqtt']
assert _setup_component(self.hass, sensor.DOMAIN, {
sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'test-topic',
'unit_of_measurement': 'fav unit'
}
}))
})
fire_mqtt_message(self.hass, 'test-topic', '100')
self.hass.pool.block_till_done()
@ -40,15 +42,16 @@ class TestSensorMQTT(unittest.TestCase):
def test_setting_sensor_value_via_mqtt_json_message(self):
"""Test the setting of the value via MQTT with JSON playload."""
self.assertTrue(sensor.setup(self.hass, {
'sensor': {
self.hass.config.components = ['mqtt']
assert _setup_component(self.hass, sensor.DOMAIN, {
sensor.DOMAIN: {
'platform': 'mqtt',
'name': 'test',
'state_topic': 'test-topic',
'unit_of_measurement': 'fav unit',
'value_template': '{{ value_json.val }}'
}
}))
})
fire_mqtt_message(self.hass, 'test-topic', '{ "val": "100" }')
self.hass.pool.block_till_done()