Add MQTT Sensor unique_id (#13318)

* Add MQTT Sensor unique_id

* Add test

* Update comment
This commit is contained in:
Otto Winter authored and Paulus Schoutsen committed 2018-04-07 22:32:09 -04:00
1 parent 99f4509c2b
commit 81b1d08d35
2 files changed
+35 -1

No files matched your search

+21
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