Reconfigure MQTT light component if discovery info is changed (#18176)

This commit is contained in:
emontnemery 2018-12-02 16:16:36 +01:00 committed by Paulus Schoutsen
parent bb13829e13
commit afa99915e3
6 changed files with 426 additions and 198 deletions

View file

@ -557,7 +557,7 @@ async def test_discovery_removal(hass, mqtt_mock, caplog):
async def test_discovery_deprecated(hass, mqtt_mock, caplog):
"""Test removal of discovered mqtt_json lights."""
"""Test discovery of mqtt_json light with deprecated platform option."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {'mqtt': {}}, entry)
data = (
@ -571,3 +571,41 @@ async def test_discovery_deprecated(hass, mqtt_mock, caplog):
state = hass.states.get('light.beer')
assert state is not None
assert state.name == 'Beer'
async def test_discovery_update_light(hass, mqtt_mock, caplog):
"""Test removal of discovered light."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
data1 = (
'{ "name": "Beer",'
' "schema": "json",'
' "status_topic": "test_topic",'
' "command_topic": "test_topic" }'
)
data2 = (
'{ "name": "Milk",'
' "schema": "json",'
' "status_topic": "test_topic",'
' "command_topic": "test_topic" }'
)
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
data1)
await hass.async_block_till_done()
state = hass.states.get('light.beer')
assert state is not None
assert state.name == 'Beer'
async_fire_mqtt_message(hass, 'homeassistant/light/bla/config',
data2)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get('light.beer')
assert state is not None
assert state.name == 'Milk'
state = hass.states.get('light.milk')
assert state is None