Cleanup if discovered mqtt binary_sensor can't be added

This commit is contained in:
emontnemery authored and Erik committed 2019-01-07 17:00:03 +01:00
1 parent dd75c49796
commit d8370f44cb
2 files changed
+45 -5

No files matched your search

+34 -1
View File
@@ -390,7 +390,7 @@ async def test_discovery_removal_binary_sensor(hass, mqtt_mock, caplog):
async def test_discovery_update_binary_sensor(hass, mqtt_mock, caplog):
"""Test removal of discovered binary_sensor."""
"""Test update of discovered binary_sensor."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
await async_start(hass, 'homeassistant', {}, entry)
data1 = (
@@ -421,6 +421,39 @@ async def test_discovery_update_binary_sensor(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",'
' "off_delay": -1 }'
)
data2 = (
'{ "name": "Milk",'
' "state_topic": "test_topic" }'
)
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
data1)
await hass.async_block_till_done()
state = hass.states.get('binary_sensor.beer')
assert state is None
async_fire_mqtt_message(hass, 'homeassistant/binary_sensor/bla/config',
data2)
await hass.async_block_till_done()
await hass.async_block_till_done()
state = hass.states.get('binary_sensor.milk')
assert state is not None
assert state.name == 'Milk'
state = hass.states.get('binary_sensor.beer')
assert state is None
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
"""Test MQTT binary sensor device registry integration."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)