(self)
Write content to the store files.
Write content to the store files.
Write content to the store files .
def write(self):
        """Write content to the store files."""
        if self.system.status.background_task:
            return

        self.logger.debug("Saving data")

        # Hacs
        path = f"{self.system.config_path}/.storage/{STORES['hacs']}"
        hacs = {"view": self.configuration.frontend_mode}
        save(path, hacs)

        # Installed
        path = f"{self.system.config_path}/.storage/{STORES['installed']}"
        installed = {}
        for repository_name in self.common.installed:
            repository = self.get_by_name(repository_name)
            if repository is None:
                self.logger.warning(f"Did not save information about {repository_name}")
                continue
            installed[repository.information.full_name] = {
                "version_type": repository.display_version_or_commit,
                "version_installed": repository.display_installed_version,
                "version_available": repository.display_available_version,
            }
        save(path, installed)

        # Repositories
        path = f"{self.system.config_path}/.storage/{STORES['repositories']}"
        content = {}
        for repository in self.repositories:
            content[repository.information.uid] = {
                "authors": repository.information.authors,
                "category": repository.information.category,
                "description": repository.information.description,
                "full_name": repository.information.full_name,
                "hide": repository.status.hide,
                "installed_commit": repository.versions.installed_commit,
                "installed": repository.status.installed,
                "last_commit": repository.versions.available_commit,
                "last_release_tag": repository.versions.available,
                "name": repository.information.name,
                "new": repository.status.new,
                "selected_tag": repository.status.selected_tag,
                "show_beta": repository.status.show_beta,
                "version_installed": repository.versions.installed,
            }

        # Validate installed repositories
        count_installed = len(installed) + 1  # For HACS it self
        count_installed_restore = 0
        for repository in self.repositories:
            if repository.status.installed:
                count_installed_restore += 1

        if count_installed < count_installed_restore:
            self.logger.debug("Save failed!")
            self.logger.debug(
                f"Number of installed repositories does not match the number of stored repositories [{count_installed} vs {count_installed_restore}]"
            )
            return
        save(path, content)
def write ( self ) : if self . system . status . background_task : return self . logger . debug ( "Saving data" ) # Hacs path = f"{self.system.config_path}/.storage/{STORES['hacs']}" hacs = { "view" : self . configuration . frontend_mode } save ( path , hacs ) # Installed path = f"{self.system.config_path}/.storage/{STORES['installed']}" installed = { } for repository_name in self . common . installed : repository = self . get_by_name ( repository_name ) if repository is None : self . logger . warning ( f"Did not save information about {repository_name}" ) continue installed [ repository . information . full_name ] = { "version_type" : repository . display_version_or_commit , "version_installed" : repository . display_installed_version , "version_available" : repository . display_available_version , } save ( path , installed ) # Repositories path = f"{self.system.config_path}/.storage/{STORES['repositories']}" content = { } for repository in self . repositories : content [ repository . information . uid ] = { "authors" : repository . information . authors , "category" : repository . information . category , "description" : repository . information . description , "full_name" : repository . information . full_name , "hide" : repository . status . hide , "installed_commit" : repository . versions . installed_commit , "installed" : repository . status . installed , "last_commit" : repository . versions . available_commit , "last_release_tag" : repository . versions . available , "name" : repository . information . name , "new" : repository . status . new , "selected_tag" : repository . status . selected_tag , "show_beta" : repository . status . show_beta , "version_installed" : repository . versions . installed , } # Validate installed repositories count_installed = len ( installed ) + 1 # For HACS it self count_installed_restore = 0 for repository in self . repositories : if repository . status . installed : count_installed_restore += 1 if count_installed < count_installed_restore : self . logger . debug ( "Save failed!" ) self . logger . debug ( f"Number of installed repositories does not match the number of stored repositories [{count_installed} vs {count_installed_restore}]" ) return save ( path , content )