Python homeassistant.config_entries.SOURCE_IMPORT Examples
The following are 13
code examples of homeassistant.config_entries.SOURCE_IMPORT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
homeassistant.config_entries
, or try the search function
.
Example #1
Source File: __init__.py From SmartHouse with MIT License | 6 votes |
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
Example #2
Source File: __init__.py From SmartHouse with MIT License | 6 votes |
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
Example #3
Source File: __init__.py From havcs with Apache License 2.0 | 6 votes |
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
Example #4
Source File: __init__.py From audi_connect_ha with MIT License | 6 votes |
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
Example #5
Source File: __init__.py From Anniversaries with MIT License | 6 votes |
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
Example #6
Source File: __init__.py From integration with MIT License | 5 votes |
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
Example #7
Source File: __init__.py From visonic with Apache License 2.0 | 5 votes |
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
Example #8
Source File: __init__.py From esxi_stats with MIT License | 5 votes |
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")
Example #9
Source File: __init__.py From havcs with Apache License 2.0 | 5 votes |
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
Example #10
Source File: config_flow.py From havcs with Apache License 2.0 | 5 votes |
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']})
Example #11
Source File: __init__.py From climate.programmable_thermostat with The Unlicense | 5 votes |
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
Example #12
Source File: __init__.py From ShellyForHASS with MIT License | 5 votes |
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
Example #13
Source File: __init__.py From Anniversaries with MIT License | 5 votes |
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