本文整理汇总了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
示例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
示例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
示例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
示例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
示例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")
示例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
示例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
示例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
示例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']})
示例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
示例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
示例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