(self)
return True
Restore saved data.
Restore saved data.
Restore saved 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.system.status.new = True
                return True
            self.logger.info("Restore started")
            self.hacs.system.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
            for entry in repositories:
                repo = repositories[entry]
                if not self.hacs.is_known(entry):
                    await register_repository(
                        repo["full_name"], repo["category"], False
                    )
                repository = [
                    x
                    for x in self.hacs.repositories
                    if str(x.data.id) == str(entry)
                    or x.data.full_name == repo["full_name"]
                ]
                if not repository:
                    self.logger.error(f"Did not find {repo['full_name']} ({entry})")
                    continue

                repository = repository[0]

                # Restore repository attributes
                repository.data.id = entry
                await self.hacs.hass.async_add_executor_job(
                    restore_repository_data, repository, repo
                )

                restored = await async_load_from_store(
                    self.hacs.hass, f"hacs/{entry}.hacs"
                )

                if restored:
                    repository.data.update_data(restored)
                    if not repository.data.installed:
                        repository.logger.debug(
                            "Should be installed but is not... Fixing that!"
                        )
                        repository.data.installed = True

            self.logger.info("Restore done")
        except Exception as exception:  # pylint: disable=broad-except
            self.logger.critical(f"[{exception}] Restore Failed!")
            return False
        return True
async def restore ( self ) : 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 . system . status . new = True return True self . logger . info ( "Restore started" ) self . hacs . system . 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 for entry in repositories : repo = repositories [ entry ] if not self . hacs . is_known ( entry ) : await register_repository ( repo [ "full_name" ] , repo [ "category" ] , False ) repository = [ x for x in self . hacs . repositories if str ( x . data . id ) == str ( entry ) or x . data . full_name == repo [ "full_name" ] ] if not repository : self . logger . error ( f"Did not find {repo['full_name']} ({entry})" ) continue repository = repository [ 0 ] # Restore repository attributes repository . data . id = entry await self . hacs . hass . async_add_executor_job ( restore_repository_data , repository , repo ) restored = await async_load_from_store ( self . hacs . hass , f"hacs/{entry}.hacs" ) if restored : repository . data . update_data ( restored ) if not repository . data . installed : repository . logger . debug ( "Should be installed but is not... Fixing that!" ) repository . data . installed = True self . logger . info ( "Restore done" ) except Exception as exception : # pylint: disable=broad-except self . logger . critical ( f"[{exception}] Restore Failed!" ) return False return True