diff --git a/API.md b/API.md index 794b99f09..57498dfcd 100644 --- a/API.md +++ b/API.md @@ -43,7 +43,9 @@ The addons from `addons` are only installed one. "repository": "12345678|null", "version": "LAST_VERSION", "installed": "INSTALL_VERSION", - "detached": "bool" + "detached": "bool", + "build": "bool", + "url": "null|url" } ], "addons_repositories": [ @@ -67,7 +69,9 @@ Get all available addons "repository": "core|local|REP_ID", "version": "LAST_VERSION", "installed": "none|INSTALL_VERSION", - "detached": "bool" + "detached": "bool", + "build": "bool", + "url": "null|url" } ], "repositories": [ @@ -224,6 +228,7 @@ Output the raw docker log "last_version": "LAST_VERSION", "state": "started|stopped", "boot": "auto|manual", + "build": "bool", "options": {}, } ``` diff --git a/hassio/addons/__init__.py b/hassio/addons/__init__.py index 9f43825c1..7abb80f0b 100644 --- a/hassio/addons/__init__.py +++ b/hassio/addons/__init__.py @@ -191,7 +191,7 @@ class AddonManager(AddonsData): return False version = version or self.get_last_version(addon) - is_running = self.dockers[addon].is_running() + is_running = await self.dockers[addon].is_running() # update if await self.dockers[addon].update(version): diff --git a/hassio/addons/data.py b/hassio/addons/data.py index 4627434b2..fe88551a0 100644 --- a/hassio/addons/data.py +++ b/hassio/addons/data.py @@ -149,12 +149,13 @@ class AddonsData(Config): """ have_change = False - for addon, data in self._system_data.items(): + for addon in self.list_installed: # detached if addon not in self._addons_cache: continue cache = self._addons_cache[addon] + data = self._system_data[addon] if data[ATTR_VERSION] == cache[ATTR_VERSION]: if data != cache: self._system_data[addon] = copy.deepcopy(cache) @@ -166,20 +167,12 @@ class AddonsData(Config): @property def list_installed(self): """Return a list of installed addons.""" - return set(self._system_data.keys()) + return set(self._system_data) @property - def data_all(self): + def list_all(self): """Return a dict of all addons.""" - return { - **self._system_data, - **self._addons_cache - } - - @property - def data_installed(self): - """Return a dict of installed addons.""" - return self._system_data.copy() + return set(self._system_data) | set(self._addons_cache) def list_startup(self, start_type): """Get list of installed addon with need start by type.""" @@ -271,21 +264,27 @@ class AddonsData(Config): def get_name(self, addon): """Return name of addon.""" + if addon in self._addons_cache: + return self._addons_cache[addon][ATTR_NAME] return self._system_data[addon][ATTR_NAME] def get_description(self, addon): """Return description of addon.""" + if addon in self._addons_cache: + return self._addons_cache[addon][ATTR_DESCRIPTON] return self._system_data[addon][ATTR_DESCRIPTON] def get_repository(self, addon): """Return repository of addon.""" + if addon in self._addons_cache: + return self._addons_cache[addon][ATTR_REPOSITORY] return self._system_data[addon][ATTR_REPOSITORY] def get_last_version(self, addon): """Return version of addon.""" - if addon not in self._addons_cache: - return self.version_installed(addon) - return self._addons_cache[addon][ATTR_VERSION] + if addon in self._addons_cache: + return self._addons_cache[addon][ATTR_VERSION] + return self.version_installed(addon) def get_ports(self, addon): """Return ports of addon.""" @@ -293,13 +292,15 @@ class AddonsData(Config): def get_url(self, addon): """Return url of addon.""" + if addon in self._addons_cache: + return self._addons_cache[addon].get(ATTR_URL) return self._system_data[addon].get(ATTR_URL) def get_arch(self, addon): """Return list of supported arch.""" - if addon not in self._addons_cache: - return self._system_data[addon][ATTR_ARCH] - return self._addons_cache[addon][ATTR_ARCH] + if addon in self._addons_cache: + return self._addons_cache[addon][ATTR_ARCH] + return self._system_data[addon][ATTR_ARCH] def get_image(self, addon): """Return image name of addon.""" diff --git a/hassio/api/addons.py b/hassio/api/addons.py index 70de3cdcb..3f15c67b1 100644 --- a/hassio/api/addons.py +++ b/hassio/api/addons.py @@ -9,7 +9,7 @@ from .util import api_process, api_process_raw, api_validate from ..const import ( ATTR_VERSION, ATTR_LAST_VERSION, ATTR_STATE, ATTR_BOOT, ATTR_OPTIONS, ATTR_URL, ATTR_DESCRIPTON, ATTR_DETACHED, ATTR_NAME, ATTR_REPOSITORY, - STATE_STOPPED, STATE_STARTED, BOOT_AUTO, BOOT_MANUAL) + ATTR_BUILD, STATE_STOPPED, STATE_STARTED, BOOT_AUTO, BOOT_MANUAL) _LOGGER = logging.getLogger(__name__) @@ -59,6 +59,7 @@ class APIAddons(object): ATTR_OPTIONS: self.addons.get_options(addon), ATTR_URL: self.addons.get_url(addon), ATTR_DETACHED: addon in self.addons.list_detached, + ATTR_BUILD: self.addons.need_build(addon), } @api_process diff --git a/hassio/api/supervisor.py b/hassio/api/supervisor.py index ac9381df6..e4e0ae32b 100644 --- a/hassio/api/supervisor.py +++ b/hassio/api/supervisor.py @@ -10,7 +10,8 @@ from ..const import ( ATTR_ADDONS, ATTR_VERSION, ATTR_LAST_VERSION, ATTR_BETA_CHANNEL, HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES, ATTR_REPOSITORY, ATTR_DESCRIPTON, ATTR_NAME, ATTR_SLUG, ATTR_INSTALLED, - ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL, ATTR_ARCH) + ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL, ATTR_ARCH, + ATTR_BUILD) _LOGGER = logging.getLogger(__name__) @@ -41,23 +42,23 @@ class APISupervisor(object): detached = self.addons.list_detached if only_installed: - addons = self.addons.data_installed + addons = self.addons.list_installed else: - addons = self.addons.data_all + addons = self.addons.list_all data = [] - for addon, values in addons.items(): - i_version = self.addons.version_installed(addon) - + for addon in addons: data.append({ - ATTR_NAME: values[ATTR_NAME], + ATTR_NAME: self.addons.get_name(addon), ATTR_SLUG: addon, - ATTR_DESCRIPTON: values[ATTR_DESCRIPTON], - ATTR_VERSION: values[ATTR_VERSION], - ATTR_INSTALLED: i_version, - ATTR_ARCH: values[ATTR_ARCH], + ATTR_DESCRIPTON: self.addons.get_description(addon), + ATTR_VERSION: self.addons.get_last_version(addon), + ATTR_INSTALLED: self.addons.version_installed(addon), + ATTR_ARCH: self.addons.get_arch(addon), ATTR_DETACHED: addon in detached, - ATTR_REPOSITORY: values[ATTR_REPOSITORY], + ATTR_REPOSITORY: self.addons.get_repository(addon), + ATTR_BUILD: self.addons.need_build(addon), + ATTR_URL: self.addons.get_url(addon), }) return data diff --git a/hassio/const.py b/hassio/const.py index bda21316d..08623b146 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -68,6 +68,7 @@ ATTR_TOTP = 'totp' ATTR_INITIALIZE = 'initialize' ATTR_SESSION = 'session' ATTR_LOCATON = 'location' +ATTR_BUILD = 'build' STARTUP_BEFORE = 'before' STARTUP_AFTER = 'after'