async def device_registry_updated(event: Event):
    if (event.data['action'] != 'update'):
        return
    registry = hass.data['device_registry']
    hass_device = registry.async_get(event.data['device_id'])
    if ((not hass_device) or (not hass_device.identifiers)):
        return
    for hass_did in hass_device.identifiers:
        if ((hass_did[0] == DOMAIN) and (hass_device.name_by_user == 'delete')):
            break
    else:
        return
    for gw in hass.data[DOMAIN].values():
        if (not isinstance(gw, Gateway3)):
            continue
        gw_device = gw.get_device(hass_did[1])
        if (not gw_device):
            continue
        if (gw_device['type'] == 'zigbee'):
            gw.debug(f"Remove device: {gw_device['did']}")
            (await gw.miio.send('remove_device', [gw_device['did']]))
        break
    registry.async_remove_device(hass_device.id)
async def device_registry_updated(event: Event):
    if (event.data['action'] != 'update'):
        return
    registry = hass.data['device_registry']
    hass_device = registry.async_get(event.data['device_id'])
    if ((not hass_device) or (not hass_device.identifiers)):
        return
    for hass_did in hass_device.identifiers:
        if ((hass_did[0] == DOMAIN) and (hass_device.name_by_user == 'delete')):
            break
    else:
        return
    for gw in hass.data[DOMAIN].values():
        if (not isinstance(gw, Gateway3)):
            continue
        gw_device = gw.get_device(hass_did[1])
        if (not gw_device):
            continue
        if (gw_device['type'] == 'zigbee'):
            gw.debug(f"Remove device: {gw_device['did']}")
            (await gw.miio.send('remove_device', [gw_device['did']]))
        break
    registry.async_remove_device(hass_device.id)