custom_components/xiaomi_miot_raw/__init__.py
async def async_setup_entry(hass, entry):
    """Set up shopping list from config flow."""
    hass.data.setdefault(DOMAIN, {})

    # entry for MiCloud login
    if 'username' in entry.data:
        return await _setup_micloud_entry(hass, entry)

    config = {}
    for item in [CONF_NAME,
                 CONF_HOST,
                 CONF_TOKEN,
                 CONF_CLOUD,
                 'cloud_write',
                 'devtype',
                 'ett_id_migrated',
                 'cloud_device_info',
                 ]:
        config[item] = entry.data.get(item)
    for item in [CONF_MAPPING,
                 CONF_CONTROL_PARAMS,
                 ]:
        config[item] = json.loads(entry.data.get(item))

    if type(entry.data.get('devtype')) == str:
        persistent_notification.async_create(
                            hass,
                            f"感谢您选择本插件！\n"
                            f"本插件最近的更新，支持了“一个设备多个类型”的配置方式，\n"
                            f"您的 **{entry.data.get(CONF_NAME)}** 配置项是旧版本格式。\n"
                            f"建议您重新添加设备，确认设备正常后删除旧设备，\n"
                            f"即可消除此提示。\n",
                            "Xiaomi MIoT")
        config[CONF_MAPPING] = {entry.data.get('devtype'): config[CONF_MAPPING]}
        config[CONF_CONTROL_PARAMS] = {entry.data.get('devtype'): config[CONF_CONTROL_PARAMS]}

    config['config_entry'] = entry
    entry_id = entry.entry_id
    unique_id = entry.unique_id
    hass.data[DOMAIN]['configs'][entry_id] = config
    hass.data[DOMAIN]['configs'][unique_id] = config

    if type(entry.data.get('devtype')) == str:
        hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, entry.data.get('devtype')))
    else:
        devtype_new = entry.data.get('devtype')
        if 'sensor' in devtype_new and 'binary_sensor' not in devtype_new:
            devtype_new += ['binary_sensor']
        for t in devtype_new:
            hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, t))

    return True
Set up shopping list from config flow.
Set up shopping list from config flow.
Set up shopping list from config flow .
async def async_setup_entry(hass, entry):
    hass.data.setdefault(DOMAIN, {})
    if 'username' in entry.data:
        return await _setup_micloud_entry(hass, entry)
    config = {}
    for item in [CONF_NAME,
                 CONF_HOST,
                 CONF_TOKEN,
                 CONF_CLOUD,
                 'cloud_write',
                 'devtype',
                 'ett_id_migrated',
                 'cloud_device_info',
                 ]:
        config[item] = entry.data.get(item)
    for item in [CONF_MAPPING,
                 CONF_CONTROL_PARAMS,
                 ]:
        config[item] = json.loads(entry.data.get(item))
    if type(entry.data.get('devtype')) == str:
        persistent_notification.async_create(
                            hass,
                            f"感谢您选择本插件！\n"
                            f"本插件最近的更新，支持了“一个设备多个类型”的配置方式，\n"
                            f"您的 **{entry.data.get(CONF_NAME)}** 配置项是旧版本格式。\n"
                            f"建议您重新添加设备，确认设备正常后删除旧设备，\n"
                            f"即可消除此提示。\n",
                            "Xiaomi MIoT")
        config[CONF_MAPPING] = {entry.data.get('devtype'): config[CONF_MAPPING]}
        config[CONF_CONTROL_PARAMS] = {entry.data.get('devtype'): config[CONF_CONTROL_PARAMS]}
    config['config_entry'] = entry
    entry_id = entry.entry_id
    unique_id = entry.unique_id
    hass.data[DOMAIN]['configs'][entry_id] = config
    hass.data[DOMAIN]['configs'][unique_id] = config
    if type(entry.data.get('devtype')) == str:
        hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, entry.data.get('devtype')))
    else:
        devtype_new = entry.data.get('devtype')
        if 'sensor' in devtype_new and 'binary_sensor' not in devtype_new:
            devtype_new += ['binary_sensor']
        for t in devtype_new:
            hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, t))
    return True
async def async_setup_entry ( hass , entry ) : hass . data . setdefault ( DOMAIN , { } ) if 'username' in entry . data : return await _setup_micloud_entry ( hass , entry ) config = { } for item in [ CONF_NAME , CONF_HOST , CONF_TOKEN , CONF_CLOUD , 'cloud_write' , 'devtype' , 'ett_id_migrated' , 'cloud_device_info' , ] : config [ item ] = entry . data . get ( item ) for item in [ CONF_MAPPING , CONF_CONTROL_PARAMS , ] : config [ item ] = json . loads ( entry . data . get ( item ) ) if type ( entry . data . get ( 'devtype' ) ) == str : persistent_notification . async_create ( hass , f"感谢您选择本插件！\n" f"本插件最近的更新，支持了“一个设备多个类型”的配置方式，\n" f"您的 **{entry.data.get(CONF_NAME)}** 配置项是旧版本格式。\n" f"建议您重新添加设备，确认设备正常后删除旧设备，\n" f"即可消除此提示。\n", "Xiaomi MIoT" ) config [ CONF_MAPPING ] = { entry . data . get ( 'devtype' ) : config [ CONF_MAPPING ] } config [ CONF_CONTROL_PARAMS ] = { entry . data . get ( 'devtype' ) : config [ CONF_CONTROL_PARAMS ] } config [ 'config_entry' ] = entry entry_id = entry . entry_id unique_id = entry . unique_id hass . data [ DOMAIN ] [ 'configs' ] [ entry_id ] = config hass . data [ DOMAIN ] [ 'configs' ] [ unique_id ] = config if type ( entry . data . get ( 'devtype' ) ) == str : hass . async_create_task ( hass . config_entries . async_forward_entry_setup ( entry , entry . data . get ( 'devtype' ) ) ) else : devtype_new = entry . data . get ( 'devtype' ) if 'sensor' in devtype_new and 'binary_sensor' not in devtype_new : devtype_new += [ 'binary_sensor' ] for t in devtype_new : hass . async_create_task ( hass . config_entries . async_forward_entry_setup ( entry , t ) ) return True
Set up shopping list from config flow.
Set up shopping list from config flow .
"""Set up shopping list from config flow.""" # entry for MiCloud login
hass
entry