mirror of
https://github.com/home-assistant/core.git
synced 2025-11-20 16:26:57 +00:00
Config validation for MQTT sensor platform.
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user