Force update support for MQTT sensor (#6492)
This commit is contained in:
parent
10f5e9744b
commit
11f11481b2
2 changed files with 71 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
|||
"""The tests for the MQTT sensor platform."""
|
||||
import unittest
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.const import EVENT_STATE_CHANGED
|
||||
from tests.common import mock_mqtt_component, fire_mqtt_message
|
||||
|
||||
from tests.common import get_test_home_assistant, mock_component
|
||||
|
@ -58,3 +60,60 @@ class TestSensorMQTT(unittest.TestCase):
|
|||
state = self.hass.states.get('sensor.test')
|
||||
|
||||
self.assertEqual('100', state.state)
|
||||
|
||||
def test_force_update_disabled(self):
|
||||
"""Test force update option."""
|
||||
mock_component(self.hass, 'mqtt')
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
sensor.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'test-topic',
|
||||
'unit_of_measurement': 'fav unit'
|
||||
}
|
||||
})
|
||||
|
||||
events = []
|
||||
|
||||
@ha.callback
|
||||
def callback(event):
|
||||
events.append(event)
|
||||
|
||||
self.hass.bus.listen(EVENT_STATE_CHANGED, callback)
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', '100')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(events))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', '100')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(events))
|
||||
|
||||
def test_force_update_enabled(self):
|
||||
"""Test force update option."""
|
||||
mock_component(self.hass, 'mqtt')
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
sensor.DOMAIN: {
|
||||
'platform': 'mqtt',
|
||||
'name': 'test',
|
||||
'state_topic': 'test-topic',
|
||||
'unit_of_measurement': 'fav unit',
|
||||
'force_update': True
|
||||
}
|
||||
})
|
||||
|
||||
events = []
|
||||
|
||||
@ha.callback
|
||||
def callback(event):
|
||||
events.append(event)
|
||||
|
||||
self.hass.bus.listen(EVENT_STATE_CHANGED, callback)
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', '100')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(1, len(events))
|
||||
|
||||
fire_mqtt_message(self.hass, 'test-topic', '100')
|
||||
self.hass.block_till_done()
|
||||
self.assertEqual(2, len(events))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue