當前位置: 首頁>>代碼示例>>Python>>正文


Python config_entries.SOURCE_IMPORT屬性代碼示例

本文整理匯總了Python中homeassistant.config_entries.SOURCE_IMPORT屬性的典型用法代碼示例。如果您正苦於以下問題:Python config_entries.SOURCE_IMPORT屬性的具體用法?Python config_entries.SOURCE_IMPORT怎麽用?Python config_entries.SOURCE_IMPORT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在homeassistant.config_entries的用法示例。


在下文中一共展示了config_entries.SOURCE_IMPORT屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass, config):
    """Set up this integration using yaml."""
    hacs = get_hacs()
    if DOMAIN not in config:
        return True
    if hacs.configuration and hacs.configuration.config_type == "flow":
        return True
    hass.data[DOMAIN] = config
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(
        config[DOMAIN], config[DOMAIN].get("options")
    )
    hacs.configuration.config = config
    hacs.configuration.config_type = "yaml"
    await startup_wrapper_for_yaml()
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
        )
    )
    return True 
開發者ID:macbury,項目名稱:SmartHouse,代碼行數:24,代碼來源:__init__.py

示例2: async_setup_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    hacs = get_hacs()
    conf = hass.data.get(DOMAIN)
    if config_entry.source == config_entries.SOURCE_IMPORT:
        if conf is None:
            hass.async_create_task(
                hass.config_entries.async_remove(config_entry.entry_id)
            )
        return False
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(
        config_entry.data, config_entry.options
    )
    hacs.configuration.config_type = "flow"
    hacs.configuration.config_entry = config_entry
    config_entry.add_update_listener(reload_hacs)
    startup_result = await hacs_startup()
    if not startup_result:
        hacs.system.disabled = True
        raise ConfigEntryNotReady
    hacs.system.disabled = False
    return startup_result 
開發者ID:macbury,項目名稱:SmartHouse,代碼行數:26,代碼來源:__init__.py

示例3: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:

    hass.data.setdefault(DOMAIN, {})
    conf = config.get(DOMAIN)  # type: ConfigType
 
    if conf is None:
        # If we have a config entry, setup is done by that config entry.
        # If there is no config entry, this should fail.
        return bool(hass.config_entries.async_entries(DOMAIN))     

    hass.data[DOMAIN][DATA_HAVCS_CONFIG] = conf

    if not [entry for entry in hass.config_entries.async_entries(DOMAIN) if entry.source == config_entries.SOURCE_IMPORT]:
        hass.async_create_task(hass.config_entries.flow.async_init(
                DOMAIN, context={'source': config_entries.SOURCE_IMPORT},
                data={'platform': conf.get(CONF_PLATFORM)}
            ))
    return True 
開發者ID:cnk700i,項目名稱:havcs,代碼行數:20,代碼來源:__init__.py

示例4: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass, config):
    if hass.config_entries.async_entries(DOMAIN):
        return True

    if DOMAIN not in config:
        return True

    names = config[DOMAIN].get(CONF_NAME)
    if len(names) == 0:
        return True

    data = {}
    data[CONF_USERNAME] = config[DOMAIN].get(CONF_USERNAME)
    data[CONF_PASSWORD] = config[DOMAIN].get(CONF_PASSWORD)
    data[CONF_SCAN_INTERVAL] = config[DOMAIN].get(CONF_SCAN_INTERVAL).seconds / 60
    data[CONF_REGION] = config[DOMAIN].get(CONF_REGION)

    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=data
        )
    )

    return True 
開發者ID:arjenvrh,項目名稱:audi_connect_ha,代碼行數:26,代碼來源:__init__.py

示例5: async_setup_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    if config_entry.source == config_entries.SOURCE_IMPORT:
        # set up using YAML
        hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
        return False
    # log startup message
    _LOGGER.info(
        CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
    )
    config_entry.options = config_entry.data
    config_entry.add_update_listener(update_listener)
    # Add sensor
    hass.async_add_job(
        hass.config_entries.async_forward_entry_setup(config_entry, PLATFORM)
    )
    return True 
開發者ID:pinkywafer,項目名稱:Anniversaries,代碼行數:19,代碼來源:__init__.py

示例6: async_remove_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_remove_entry(hass, config_entry):
    """Handle removal of an entry."""
    if hass.data.get(DOMAIN_DATA, {}).get("configuration") == "yaml":
        hass.async_create_task(
            hass.config_entries.flow.async_init(
                DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
            )
        )
    else:
        for plafrom in PLATFORMS:
            await hass.config_entries.async_forward_entry_unload(config_entry, plafrom)
        _LOGGER.info("Successfully removed the ESXi Stats integration") 
開發者ID:wxt9861,項目名稱:esxi_stats,代碼行數:14,代碼來源:__init__.py

示例7: async_setup_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    hacs = get_hacs()
    conf = hass.data.get(DOMAIN)
    if conf is not None:
        return False
    if config_entry.source == config_entries.SOURCE_IMPORT:
        hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
        return False
    hacs.hass = hass
    hacs.session = async_create_clientsession(hass)
    hacs.configuration = Configuration.from_dict(
        config_entry.data, config_entry.options
    )
    hacs.configuration.config_type = "flow"
    hacs.configuration.config_entry = config_entry
    config_entry.add_update_listener(reload_hacs)
    try:
        startup_result = await hacs_startup()
    except AIOGitHubAPIException:
        startup_result = False
    if not startup_result:
        hacs.system.disabled = True
        raise ConfigEntryNotReady
    hacs.system.disabled = False
    return startup_result 
開發者ID:hacs,項目名稱:integration,代碼行數:28,代碼來源:__init__.py

示例8: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass: HomeAssistant, base_config: dict):
    """Set up the visonic component."""
    # initially empty the settings for this component
    hass.data[DOMAIN] = {}
    hass.data[DOMAIN][DOMAINDATA] = {}
    hass.data[DOMAIN][DOMAINCLIENT] = {}

    # if there are no configuration.yaml settings then terminate
    if DOMAIN not in base_config:
        return True

    # has there been a flow configured panel connection before    
    configured = configured_hosts(hass)
        
    # if there is not a flow configured connection previously
    #   then create a flow connection from the configuration.yaml data
    if len(configured) == 0:
        # get the configuration.yaml settings and make a 'flow' task :)
        #   this will run 'async_step_import' in config_flow.py
        conf = base_config.get(DOMAIN)
        log.info("      Adding job")
        # hass.async_add_job (
        hass.async_create_task (
            hass.config_entries.flow.async_init(
                DOMAIN, 
                context={"source": config_entries.SOURCE_IMPORT},
                data=conf
            )
        )
    return True

# This function is called with the flow data to create a client connection to the alarm panel
# from one of:
#    - the imported configuration.yaml values that have created a control flow
#    - the original control flow if it existed 
開發者ID:davesmeghead,項目名稱:visonic,代碼行數:37,代碼來源:__init__.py

示例9: async_unload_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_unload_entry(hass, config_entry):
    if config_entry.source in [config_entries.SOURCE_IMPORT, config_entries.SOURCE_USER]:
        tasks = [hass.config_entries.async_remove(entry.entry_id) for entry in hass.config_entries.async_entries(DOMAIN) if entry.source == SOURCE_PLATFORM and entry.data['platform'] in config_entry.data['platform']]
        if tasks:
            unload_ok = all(await asyncio.gather(*tasks))
        else:
            unload_ok =True
        if unload_ok:
            hass.services.async_remove(DOMAIN, SERVICE_RELOAD)
            hass.services.async_remove(DOMAIN, SERVICE_DEBUG_DISCOVERY)
            if DATA_HAVCS_MQTT in hass.data[DOMAIN]:
                await hass.data[DOMAIN][DATA_HAVCS_MQTT].async_disconnect()
                hass.data[DOMAIN].pop(DATA_HAVCS_MQTT)
            if DATA_HAVCS_BIND_MANAGER in hass.data[DOMAIN]:
                hass.data[DOMAIN][DATA_HAVCS_BIND_MANAGER].clear()
            hass.data[DOMAIN].pop(DATA_HAVCS_CONFIG)
            # hass.data[DOMAIN].pop(DATA_HAVCS_ITEMS)
            hass.data[DOMAIN].pop(DATA_HAVCS_HANDLER)
            hass.data[DOMAIN].pop(DATA_HAVCS_HTTP_MANAGER)
            hass.data[DOMAIN].pop(CONF_DEVICE_CONFIG_PATH)
            hass.components.frontend.async_remove_panel(DOMAIN)
            if not hass.data[DOMAIN]:
                hass.data.pop(DOMAIN)
            
        return unload_ok

    elif config_entry.source == SOURCE_PLATFORM:
        for entry in [entry for entry in hass.config_entries.async_entries(DOMAIN) if entry.source in [config_entries.SOURCE_IMPORT, config_entries.SOURCE_USER]]:
            if config_entry.data['platform'] in entry.data['platform']:
                entry.data['platform'].remove(config_entry.data['platform'])
        return True 
開發者ID:cnk700i,項目名稱:havcs,代碼行數:33,代碼來源:__init__.py

示例10: async_step_import

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_step_import(self, user_input):
        """Import a config entry.

        Special type of import, we're not actually going to store any data.
        Instead, we're going to rely on the values that are in config file.
        """
        if [entry for entry in self._async_current_entries() if entry.source in [config_entries.SOURCE_USER, config_entries.SOURCE_IMPORT]]:
            return self.async_abort(reason='single_instance_allowed') 
        return self.async_create_entry(title='主配置[configuration.yml]', data={'platform': user_input['platform']}) 
開發者ID:cnk700i,項目名稱:havcs,代碼行數:11,代碼來源:config_flow.py

示例11: async_setup_entry

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup_entry(hass, config_entry):
    """Set up this integration using UI."""
    if config_entry.source == config_entries.SOURCE_IMPORT:
        # We get here if the integration is set up using YAML
        hass.async_create_task(hass.config_entries.async_remove(config_entry.entry_id))
        return True
    undo_listener = config_entry.add_update_listener(update_listener)
    _LOGGER.info("Added new ProgrammableThermostat entity, entry_id: %s", config_entry.entry_id)
    hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, PLATFORM))

    return True 
開發者ID:custom-components,項目名稱:climate.programmable_thermostat,代碼行數:13,代碼來源:__init__.py

示例12: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass, config):
    """Set up this integration using yaml."""
    if DOMAIN not in config:
        return True
    data = dict(config.get(DOMAIN))
    hass.data["yaml_shelly"] = data
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
        )
    )
    return True 
開發者ID:StyraHem,項目名稱:ShellyForHASS,代碼行數:14,代碼來源:__init__.py

示例13: async_setup

# 需要導入模塊: from homeassistant import config_entries [as 別名]
# 或者: from homeassistant.config_entries import SOURCE_IMPORT [as 別名]
def async_setup(hass, config):
    """Set up this component using YAML."""
    if config.get(DOMAIN) is None:
        # config flow setup
        return True

    # log startup message
    _LOGGER.info(
        CC_STARTUP_VERSION.format(name=DOMAIN, version=VERSION, issue_link=ISSUE_URL)
    )
    platform_config = config[DOMAIN].get(CONF_SENSORS, {})

    # If platform is not enabled, skip.
    if not platform_config:
        return False

    for entry in platform_config:
        hass.async_create_task(
            discovery.async_load_platform(hass, PLATFORM, DOMAIN, entry, config)
        )
    hass.async_create_task(
        hass.config_entries.flow.async_init(
            DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={}
        )
    )
    return True 
開發者ID:pinkywafer,項目名稱:Anniversaries,代碼行數:28,代碼來源:__init__.py


注:本文中的homeassistant.config_entries.SOURCE_IMPORT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。