Cleanup if discovered mqtt switch can't be added (#19721)

* Cleanup if discovered mqtt switch can't be added
This commit is contained in:
emontnemery authored and GitHub committed 2019-01-07 16:57:51 +01:00
1 parent 8b232e7ce6
commit dd75c49796
4 files changed
+53 -8

No files matched your search

+35 -2
View File
@@ -285,7 +285,7 @@ async def test_unique_id(hass):
async def test_discovery_removal_switch(hass, mqtt_mock, caplog):
"""Test expansion of discovered switch."""
"""Test removal of discovered switch."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
@@ -314,7 +314,7 @@ async def test_discovery_removal_switch(hass, mqtt_mock, caplog):
async def test_discovery_update_switch(hass, mqtt_mock, caplog):
"""Test expansion of discovered switch."""
"""Test update of discovered switch."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
@@ -349,6 +349,39 @@ async def test_discovery_update_switch(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",'
' "status_topic": "test_topic",'
' "command_topic": "test_topic" }'
)
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
data1)
await hass.async_block_till_done()
state = hass.states.get('switch.beer')
assert state is None
async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config',
data2)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get('switch.milk')
assert state is not None
assert state.name == 'Milk'
state = hass.states.get('switch.beer')
assert state is None
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
"""Test MQTT switch device registry integration."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)