1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Cleanup if discovered mqtt light can't be added (#19740)

* Cleanup if discovered mqtt light can't be added

* No bare except

* Clear ALREADY_DISCOVERED list with helper

* Use constant instead of string literal
This commit is contained in:
emontnemery
2019-01-25 14:40:52 +08:00
committed by Paulus Schoutsen
parent a1da6a677a
commit d84cd01cbf
7 changed files with 132 additions and 16 deletions

View File

@@ -707,7 +707,7 @@ async def test_discovery_deprecated(hass, mqtt_mock, caplog):
async def test_discovery_update_light(hass, mqtt_mock, caplog):
"""Test removal of discovered light."""
"""Test update of discovered light."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
@@ -744,6 +744,40 @@ async def test_discovery_update_light(hass, mqtt_mock, caplog):
assert state is None
async def test_discovery_broken(hass, mqtt_mock, caplog):
"""Test handling of bad discovery message."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
data1 = (
'{ "name": "Beer" }'
)
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 None
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.milk')
assert state is not None
assert state.name == 'Milk'
state = hass.states.get('light.beer')
assert state is None
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
"""Test MQTT light device registry integration."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)