async def test_discovery_update_switch(hass, mqtt_mock, caplog):
    'Test update of discovered switch.'
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    (await async_start(hass, 'homeassistant', {}, entry))
    data1 = '{ "name": "Beer",  "state_topic": "test_topic",  "command_topic": "test_topic" }'
    data2 = '{ "name": "Milk",  "state_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 not None)
    assert (state.name == 'Beer')
    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.beer')
    assert (state is not None)
    assert (state.name == 'Milk')
    state = hass.states.get('switch.milk')
    assert (state is None)
Test update of discovered switch.
async def test_discovery_update_switch(hass, mqtt_mock, caplog):
    
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    (await async_start(hass, 'homeassistant', {}, entry))
    data1 = '{ "name": "Beer",  "state_topic": "test_topic",  "command_topic": "test_topic" }'
    data2 = '{ "name": "Milk",  "state_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 not None)
    assert (state.name == 'Beer')
    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.beer')
    assert (state is not None)
    assert (state.name == 'Milk')
    state = hass.states.get('switch.milk')
    assert (state is None)