Add unique_id for mqtt binary sensor (#14929)

* Added unique_id for mqtt binary sensor

* Added missing mqtt message fire in test
This commit is contained in:
Marius 2018-06-13 17:20:38 +03:00 committed by Martin Hjelmare
parent 65b0ec6615
commit 08adfd87f7
2 changed files with 34 additions and 3 deletions

View file

@ -77,6 +77,25 @@ class TestSensorMQTT(unittest.TestCase):
state = self.hass.states.get('binary_sensor.test')
self.assertIsNone(state)
def test_unique_id(self):
"""Test unique id option only creates one sensor per unique_id."""
assert setup_component(self.hass, binary_sensor.DOMAIN, {
binary_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
def test_availability_without_topic(self):
"""Test availability without defined availability topic."""
self.assertTrue(setup_component(self.hass, binary_sensor.DOMAIN, {