async def restore(self): """Restore saved data.""" hacs = await async_load_from_store(self.hacs.hass, "hacs") repositories = await async_load_from_store(self.hacs.hass, "repositories") or {} if not hacs and not repositories: # Assume new install self.hacs.status.new = True return True self.logger.info("Restore started") self.hacs.status.new = False # Hacs self.hacs.configuration.frontend_mode = hacs.get("view", "Grid") self.hacs.configuration.frontend_compact = hacs.get("compact", False) self.hacs.configuration.onboarding_done = hacs.get( "onboarding_done", False) self.hacs.common.archived_repositories = hacs.get( "archived_repositories", []) self.hacs.common.renamed_repositories = hacs.get( "renamed_repositories", {}) hass = self.hacs.hass stores = {} try: await self.register_unknown_repositories(repositories) for entry, repo_data in repositories.items(): if entry == "0": # Ignore repositories with ID 0 self.logger.error("Found repository with ID %s - %s", entry, repo_data) continue if self.async_restore_repository(entry, repo_data): stores[entry] = get_store_for_key(hass, f"hacs/{entry}.hacs") def _load_from_storage(): for entry, store in stores.items(): if os.path.exists(store.path) and (data := store.load()): if (full_name := data.get("full_name")) and ( renamed := self.hacs.common.renamed_repositories.get( full_name)) is not None: data["full_name"] = renamed update_repository_from_storage( self.hacs.get_by_id(entry), data)
async def restore(self): """Restore saved data.""" hacs = await async_load_from_store(self.hacs.hass, "hacs") repositories = await async_load_from_store(self.hacs.hass, "repositories") try: if not hacs and not repositories: # Assume new install self.hacs.status.new = True return True self.logger.info("Restore started") self.hacs.status.new = False # Hacs self.hacs.configuration.frontend_mode = hacs.get("view", "Grid") self.hacs.configuration.frontend_compact = hacs.get( "compact", False) self.hacs.configuration.onboarding_done = hacs.get( "onboarding_done", False) # Repositories stores = {} for entry in repositories or []: stores[entry] = get_store_for_key(self.hacs.hass, f"hacs/{entry}.hacs") stores_exist = {} def _populate_stores(): for entry in repositories or []: stores_exist[entry] = os.path.exists(stores[entry].path) await self.hacs.hass.async_add_executor_job(_populate_stores) # Repositories for entry in repositories or []: self.queue.add( self.async_restore_repository(entry, repositories[entry], stores[entry], stores_exist[entry])) await self.queue.execute() self.logger.info("Restore done") except (Exception, BaseException) as exception: # pylint: disable=broad-except self.logger.critical(f"[{exception}] Restore Failed!") return False return True
async def restore(self): """Restore saved data.""" hacs = await async_load_from_store(self.hacs.hass, "hacs") repositories = await async_load_from_store(self.hacs.hass, "repositories") or {} if not hacs and not repositories: # Assume new install self.hacs.status.new = True return True self.logger.info("Restore started") self.hacs.status.new = False # Hacs self.hacs.configuration.frontend_mode = hacs.get("view", "Grid") self.hacs.configuration.frontend_compact = hacs.get("compact", False) self.hacs.configuration.onboarding_done = hacs.get( "onboarding_done", False) self.hacs.common.archived_repositories = hacs.get( "archived_repositories", []) self.hacs.common.renamed_repositories = hacs.get( "renamed_repositories", {}) # Repositories hass = self.hacs.hass stores = {} try: await self.register_unknown_repositories(repositories) for entry, repo_data in repositories.items(): if self.async_restore_repository(entry, repo_data): stores[entry] = get_store_for_key(hass, f"hacs/{entry}.hacs") def _load_from_storage(): for entry, store in stores.items(): if os.path.exists(store.path) and (data := store.load()): update_repository_from_storage( self.hacs.get_by_id(entry), data) await hass.async_add_executor_job(_load_from_storage) self.logger.info("Restore done")