Add MQTT Sensor unique_id (#13318)

* Add MQTT Sensor unique_id

* Add test

* Update comment
This commit is contained in:
Otto Winter 2018-04-08 04:32:09 +02:00 committed by Paulus Schoutsen
parent 99f4509c2b
commit 81b1d08d35
2 changed files with 35 additions and 1 deletions

View file

@ -329,3 +329,24 @@ class TestSensorMQTT(unittest.TestCase):
self.assertEqual('100',
state.attributes.get('val'))
self.assertEqual('100', state.state)
def test_unique_id(self):
"""Test unique id option only creates one sensor per unique_id."""
assert setup_component(self.hass, sensor.DOMAIN, {
sensor.DOMAIN: [{
'platform': 'mqtt',
'name': 'Test 1',
'state_topic': 'test-topic',
'unique_id': 'TOTALLY_UNIQUE'
}, {
'platform': 'mqtt',
'name': 'Test 2',
'state_topic': 'test-topic',
'unique_id': 'TOTALLY_UNIQUE'
}]
})
fire_mqtt_message(self.hass, 'test-topic', 'payload')
self.hass.block_till_done()
assert len(self.hass.states.all()) == 1