async def test_entity_id_update(hass, mqtt_mock):
    'Test MQTT subscriptions are managed when entity_id is updated.'
    registry = mock_registry(hass, {})
    mock_mqtt = (await async_mock_mqtt_component(hass))
    assert (await async_setup_component(hass, switch.DOMAIN, {switch.DOMAIN: [{'platform': 'mqtt', 'name': 'beer', 'state_topic': 'test-topic', 'command_topic': 'command-topic', 'availability_topic': 'avty-topic', 'unique_id': 'TOTALLY_UNIQUE'}]}))
    state = hass.states.get('switch.beer')
    assert (state is not None)
    assert (mock_mqtt.async_subscribe.call_count == 2)
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.reset_mock()
    registry.async_update_entity('switch.beer', new_entity_id='switch.milk')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert (state is None)
    state = hass.states.get('switch.milk')
    assert (state is not None)
    assert (mock_mqtt.async_subscribe.call_count == 2)
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
Test MQTT subscriptions are managed when entity_id is updated.
async def test_entity_id_update(hass, mqtt_mock):
    
    registry = mock_registry(hass, {})
    mock_mqtt = (await async_mock_mqtt_component(hass))
    assert (await async_setup_component(hass, switch.DOMAIN, {switch.DOMAIN: [{'platform': 'mqtt', 'name': 'beer', 'state_topic': 'test-topic', 'command_topic': 'command-topic', 'availability_topic': 'avty-topic', 'unique_id': 'TOTALLY_UNIQUE'}]}))
    state = hass.states.get('switch.beer')
    assert (state is not None)
    assert (mock_mqtt.async_subscribe.call_count == 2)
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.reset_mock()
    registry.async_update_entity('switch.beer', new_entity_id='switch.milk')
    (await hass.async_block_till_done())
    (await hass.async_block_till_done())
    state = hass.states.get('switch.beer')
    assert (state is None)
    state = hass.states.get('switch.milk')
    assert (state is not None)
    assert (mock_mqtt.async_subscribe.call_count == 2)
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')