diff --git a/API.md b/API.md index 8a16774a8..17c6c660b 100644 --- a/API.md +++ b/API.md @@ -299,7 +299,8 @@ Get all available addons "installed": "none|INSTALL_VERSION", "detached": "bool", "build": "bool", - "url": "null|url" + "url": "null|url", + "logo": "bool" } ], "repositories": [ diff --git a/hassio/addons/addon.py b/hassio/addons/addon.py index 07b3fd9ee..364c4a348 100644 --- a/hassio/addons/addon.py +++ b/hassio/addons/addon.py @@ -19,7 +19,7 @@ from ..const import ( ATTR_URL, ATTR_ARCH, ATTR_LOCATON, ATTR_DEVICES, ATTR_ENVIRONMENT, ATTR_HOST_NETWORK, ATTR_TMPFS, ATTR_PRIVILEGED, ATTR_STARTUP, STATE_STARTED, STATE_STOPPED, STATE_NONE, ATTR_USER, ATTR_SYSTEM, - ATTR_STATE, ATTR_TIMEOUT, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_LOGO) + ATTR_STATE, ATTR_TIMEOUT, ATTR_AUTO_UPDATE, ATTR_NETWORK) from .util import check_installed from ..dock.addon import DockerAddon from ..tools import write_json_file, read_json_file @@ -130,7 +130,8 @@ class Addon(object): @property def auto_update(self): """Return if auto update is enable.""" - return self.data.user[self._id][ATTR_AUTO_UPDATE] + if ATTR_AUTO_UPDATE in self.data.user.get(self._id, {}): + return self.data.user[self._id][ATTR_AUTO_UPDATE] @auto_update.setter def auto_update(self, value): diff --git a/hassio/api/addons.py b/hassio/api/addons.py index 0083d05b1..23cc405a3 100644 --- a/hassio/api/addons.py +++ b/hassio/api/addons.py @@ -11,7 +11,8 @@ from ..const import ( ATTR_URL, ATTR_DESCRIPTON, ATTR_DETACHED, ATTR_NAME, ATTR_REPOSITORY, ATTR_BUILD, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_HOST_NETWORK, ATTR_SLUG, ATTR_SOURCE, ATTR_REPOSITORIES, ATTR_ADDONS, ATTR_ARCH, ATTR_MAINTAINER, - ATTR_INSTALLED, ATTR_LOGO, BOOT_AUTO, BOOT_MANUAL, CONTENT_TYPE_PNG) + ATTR_INSTALLED, ATTR_LOGO, BOOT_AUTO, BOOT_MANUAL, CONTENT_TYPE_PNG, + CONTENT_TYPE_BINARY) from ..validate import DOCKER_PORTS _LOGGER = logging.getLogger(__name__) @@ -107,6 +108,7 @@ class APIAddons(object): ATTR_BUILD: addon.need_build, ATTR_NETWORK: addon.ports, ATTR_HOST_NETWORK: addon.network_mode == 'host', + ATTR_LOGO: addon.with_logo, } @api_process @@ -183,7 +185,7 @@ class APIAddons(object): addon = self._extract_addon(request) return await asyncio.shield(addon.restart(), loop=self.loop) - @api_process_raw + @api_process_raw(CONTENT_TYPE_BINARY) def logs(self, request): """Return logs from addon.""" addon = self._extract_addon(request) @@ -192,8 +194,8 @@ class APIAddons(object): @api_process_raw(CONTENT_TYPE_PNG) async def logo(self, request): """Return logo from addon.""" - addon = self._extract_addon(request) - if addon.with_logo: + addon = self._extract_addon(request, check_installed=False) + if not addon.with_logo: raise RuntimeError("No image found!") with addon.path_logo.open('rb') as png: diff --git a/hassio/api/homeassistant.py b/hassio/api/homeassistant.py index 9b10497ca..6910a920c 100644 --- a/hassio/api/homeassistant.py +++ b/hassio/api/homeassistant.py @@ -6,7 +6,8 @@ import voluptuous as vol from .util import api_process, api_process_raw, api_validate from ..const import ( - ATTR_VERSION, ATTR_LAST_VERSION, ATTR_DEVICES, ATTR_IMAGE, ATTR_CUSTOM) + ATTR_VERSION, ATTR_LAST_VERSION, ATTR_DEVICES, ATTR_IMAGE, ATTR_CUSTOM, + CONTENT_TYPE_BINARY) from ..validate import HASS_DEVICES _LOGGER = logging.getLogger(__name__) @@ -79,7 +80,7 @@ class APIHomeAssistant(object): return await asyncio.shield( self.homeassistant.restart(), loop=self.loop) - @api_process_raw + @api_process_raw(CONTENT_TYPE_BINARY) def logs(self, request): """Return homeassistant docker logs. diff --git a/hassio/api/supervisor.py b/hassio/api/supervisor.py index 2313ed111..52b49b922 100644 --- a/hassio/api/supervisor.py +++ b/hassio/api/supervisor.py @@ -10,7 +10,7 @@ from ..const import ( 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_BUILD, ATTR_TIMEZONE) + ATTR_BUILD, ATTR_TIMEZONE, CONTENT_TYPE_BINARY) from ..tools import validate_timezone _LOGGER = logging.getLogger(__name__) @@ -150,7 +150,7 @@ class APISupervisor(object): return True - @api_process_raw + @api_process_raw(CONTENT_TYPE_BINARY) def logs(self, request): """Return supervisor docker logs. diff --git a/hassio/api/util.py b/hassio/api/util.py index 3f837d2a5..671073c1d 100644 --- a/hassio/api/util.py +++ b/hassio/api/util.py @@ -66,21 +66,23 @@ def api_process_hostcontrol(method): return wrap_hostcontrol -def api_process_raw(content=CONTENT_TYPE_BINARY): - def api_raw(method): +def api_process_raw(content): + """Wrap content_type into function.""" + def wrap_method(method): """Wrap function with raw output to rest api.""" async def wrap_api(api, *args, **kwargs): """Return api information.""" try: - message = await method(api, *args, **kwargs) + msg_data = await method(api, *args, **kwargs) + msg_type = content except RuntimeError as err: - message = str(err).encode() - content = CONTENT_TYPE_BINARY + msg_data = str(err).encode() + msg_type = CONTENT_TYPE_BINARY - return web.Response(body=message, content_type=content) + return web.Response(body=msg_data, content_type=msg_type) return wrap_api - return api_raw + return wrap_method def api_return_error(message=None):