async def _setup_micloud_entry(hass: HomeAssistant, config_entry):
    data: dict = config_entry.data.copy()
    session = async_create_clientsession(hass)
    hass.data[DOMAIN]['cloud'] = cloud = MiCloud(session, data['servers'])
    if ('service_token' in data):
        cloud.auth = data
        devices = (await cloud.get_devices())
    else:
        devices = None
    if (devices is None):
        _LOGGER.debug(f'Login to MiCloud for {config_entry.title}')
        if (await cloud.login(data['username'], data['password'])):
            data.update(cloud.auth)
            hass.config_entries.async_update_entry(config_entry, data=data)
            devices = (await cloud.get_devices())
            if (devices is None):
                _LOGGER.error("Can't load devices from MiCloud")
        else:
            _LOGGER.error("Can't login to MiCloud")
    store = Store(hass, 1, f"{DOMAIN}/{data['username']}.json")
    if (devices is None):
        _LOGGER.debug('Loading a list of devices from the .storage')
        devices = (await store.async_load())
    else:
        _LOGGER.debug(f'Loaded from MiCloud {len(devices)} devices')
        (await store.async_save(devices))
    if (devices is None):
        _LOGGER.debug('No devices in .storage')
        return False
    if ('devices' not in hass.data[DOMAIN]):
        hass.data[DOMAIN]['devices'] = devices
    else:
        hass.data[DOMAIN]['devices'] += devices
    for device in devices:
        did = (device['did'] if (device['pid'] not in '6') else device['mac'].replace(':', '').lower())
        DevicesRegistry.defaults.setdefault(did, {})
        DevicesRegistry.defaults[did].setdefault('device_name', device['name'])
    return True
async def _setup_micloud_entry(hass: HomeAssistant, config_entry):
    data: dict = config_entry.data.copy()
    session = async_create_clientsession(hass)
    hass.data[DOMAIN]['cloud'] = cloud = MiCloud(session, data['servers'])
    if ('service_token' in data):
        cloud.auth = data
        devices = (await cloud.get_devices())
    else:
        devices = None
    if (devices is None):
        _LOGGER.debug(f'Login to MiCloud for {config_entry.title}')
        if (await cloud.login(data['username'], data['password'])):
            data.update(cloud.auth)
            hass.config_entries.async_update_entry(config_entry, data=data)
            devices = (await cloud.get_devices())
            if (devices is None):
                _LOGGER.error("Can't load devices from MiCloud")
        else:
            _LOGGER.error("Can't login to MiCloud")
    store = Store(hass, 1, f"{DOMAIN}/{data['username']}.json")
    if (devices is None):
        _LOGGER.debug('Loading a list of devices from the .storage')
        devices = (await store.async_load())
    else:
        _LOGGER.debug(f'Loaded from MiCloud {len(devices)} devices')
        (await store.async_save(devices))
    if (devices is None):
        _LOGGER.debug('No devices in .storage')
        return False
    if ('devices' not in hass.data[DOMAIN]):
        hass.data[DOMAIN]['devices'] = devices
    else:
        hass.data[DOMAIN]['devices'] += devices
    for device in devices:
        did = (device['did'] if (device['pid'] not in '6') else device['mac'].replace(':', ).lower())
        DevicesRegistry.defaults.setdefault(did, {})
        DevicesRegistry.defaults[did].setdefault('device_name', device['name'])
    return True