async def _async_get_custom_components( opp: OpenPeerPower, ) -> dict[str, Integration]: """Return list of custom integrations.""" if opp.config.safe_mode: return {} try: import custom_components # pylint: disable=import-outside-toplevel except ImportError: return {} def get_sub_directories(paths: list[str]) -> list[pathlib.Path]: """Return all sub directories in a set of paths.""" return [ entry for path in paths for entry in pathlib.Path(path).iterdir() if entry.is_dir() ] dirs = await opp.async_add_executor_job(get_sub_directories, custom_components.__path__) integrations = await gather_with_concurrency( MAX_LOAD_CONCURRENTLY, *(opp.async_add_executor_job(Integration.resolve_from_root, opp, custom_components, comp.name) for comp in dirs), ) return { integration.domain: integration for integration in integrations if integration is not None }
async def async_unload_entry(opp: OpenPeerPower, entry: ConfigEntry) -> bool: """Unload a config entry.""" unload = await opp.config_entries.async_unload_platforms(entry, PLATFORMS) await asyncio.gather(*[ opp.async_add_executor_job(gateway.websocket_disconnect) for gateway in opp.data[DOMAIN][entry.entry_id]["gateways"] ]) opp.data[DOMAIN][entry.entry_id]["listener"]() opp.data[DOMAIN].pop(entry.entry_id) return unload
async def async_unload_entry(opp: OpenPeerPower, config_entry: ConfigEntry) -> bool: """Unload Withings config entry.""" controller_data: ControllerData = get_controller_data(opp, config_entry) tasks = [ opp.config_entries.async_forward_entry_unload(config_entry, platform) for platform in get_configured_platforms(controller_data) ] tasks.append(opp.async_add_executor_job(controller_data.controller.stop)) await asyncio.gather(*tasks) return True
async def async_get_component_strings(opp: OpenPeerPower, language: str, components: set[str]) -> dict[str, Any]: """Load translations.""" domains = list({loaded.split(".")[-1] for loaded in components}) integrations = dict( zip( domains, await gather_with_concurrency( MAX_LOAD_CONCURRENTLY, *[async_get_integration(opp, domain) for domain in domains], ), )) translations: dict[str, Any] = {} # Determine paths of missing components/platforms files_to_load = {} for loaded in components: parts = loaded.split(".") domain = parts[-1] integration = integrations[domain] path = component_translation_path(loaded, language, integration) # No translation available if path is None: translations[loaded] = {} else: files_to_load[loaded] = path if not files_to_load: return translations # Load files load_translations_job = opp.async_add_executor_job(load_translations_files, files_to_load) assert load_translations_job is not None loaded_translations = await load_translations_job # Translations that miss "title" will get integration put in. for loaded, loaded_translation in loaded_translations.items(): if "." in loaded: continue if "title" not in loaded_translation: loaded_translation["title"] = integrations[loaded].name translations.update(loaded_translations) return translations