async def test_discovery_update_attr(hass, mqtt_mock, caplog):
    'Test update of discovered MQTTAttributes.'
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    (await async_start(hass, 'homeassistant', {}, entry))
    data1 = '{ "name": "Beer",  "command_topic": "test_topic",  "json_attributes_topic": "attr-topic1" }'
    data2 = '{ "name": "Beer",  "command_topic": "test_topic",  "json_attributes_topic": "attr-topic2" }'
    async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config', data1)
    (await hass.async_block_till_done())
    async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('100' == state.attributes.get('val'))
    async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config', data2)
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('100' == state.attributes.get('val'))
    async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('75' == state.attributes.get('val'))
Test update of discovered MQTTAttributes.
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
    
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    (await async_start(hass, 'homeassistant', {}, entry))
    data1 = '{ "name": "Beer",  "command_topic": "test_topic",  "json_attributes_topic": "attr-topic1" }'
    data2 = '{ "name": "Beer",  "command_topic": "test_topic",  "json_attributes_topic": "attr-topic2" }'
    async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config', data1)
    (await hass.async_block_till_done())
    async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "100" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('100' == state.attributes.get('val'))
    async_fire_mqtt_message(hass, 'homeassistant/switch/bla/config', data2)
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    async_fire_mqtt_message(hass, 'attr-topic1', '{ "val": "50" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('100' == state.attributes.get('val'))
    async_fire_mqtt_message(hass, 'attr-topic2', '{ "val": "75" }')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert ('75' == state.attributes.get('val'))