Fix discovery update of MQTT light (#39325)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-09-02 10:52:33 +02:00
1 parent e55a014e94
commit 4c6960ed36
6 files changed
+105 -69

No files matched your search

+32 -3
View File
@@ -503,7 +503,20 @@ async def help_test_discovery_removal(hass, mqtt_mock, caplog, domain, data):
assert state is None
async def help_test_discovery_update(hass, mqtt_mock, caplog, domain, data1, data2):
async def help_test_discovery_update(
hass,
mqtt_mock,
caplog,
domain,
discovery_data1,
discovery_data2,
state_data1=None,
state_data2=None,
state1=None,
state2=None,
attributes1=None,
attributes2=None,
):
"""Test update of discovered component.
This is a test helper for the MqttDiscoveryUpdate mixin.
@@ -511,19 +524,35 @@ async def help_test_discovery_update(hass, mqtt_mock, caplog, domain, data1, dat
entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
await async_start(hass, "homeassistant", entry)
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1)
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", discovery_data1)
await hass.async_block_till_done()
if state_data1:
for (topic, data) in state_data1:
async_fire_mqtt_message(hass, topic, data)
state = hass.states.get(f"{domain}.beer")
assert state is not None
assert state.name == "Beer"
if state1:
assert state.state == state1
if attributes1:
for (attr, value) in attributes1:
assert state.attributes.get(attr) == value
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data2)
async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", discovery_data2)
await hass.async_block_till_done()
if state_data2:
for (topic, data) in state_data2:
async_fire_mqtt_message(hass, topic, data)
state = hass.states.get(f"{domain}.beer")
assert state is not None
assert state.name == "Milk"
if state2:
assert state.state == state2
if attributes2:
for (attr, value) in attributes2:
assert state.attributes.get(attr) == value
state = hass.states.get(f"{domain}.milk")
assert state is None