From c76408e4e8d339649c151c295ef6e9c3f06601b7 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sun, 30 Apr 2017 22:15:03 +0200 Subject: [PATCH] Move list of all available addons to own api call (#24) * Move list of all available addons to own api call * fix lint * fix lint * fix style --- API.md | 21 ++++++++++++++++++++- hassio/api/__init__.py | 2 ++ hassio/api/supervisor.py | 7 ++++++- hassio/api/util.py | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 1077ee721..96eaf1ab8 100644 --- a/API.md +++ b/API.md @@ -26,6 +26,8 @@ On success - GET `/supervisor/info` +The addons from `addons` are only installed one. + ```json { "version": "INSTALL_VERSION", @@ -36,7 +38,7 @@ On success "name": "xy bla", "slug": "xy", "version": "LAST_VERSION", - "installed": "none|INSTALL_VERSION", + "installed": "INSTALL_VERSION", "dedicated": "bool", "description": "description" } @@ -47,6 +49,23 @@ On success } ``` +- GET `/supervisor/addons` + +Get all available addons + +```json +[ + { + "name": "xy bla", + "slug": "xy", + "version": "LAST_VERSION", + "installed": "none|INSTALL_VERSION", + "dedicated": "bool", + "description": "description" + } +] +``` + - POST `/supervisor/update` Optional: ```json diff --git a/hassio/api/__init__.py b/hassio/api/__init__.py index c3460aa60..2ee224ab9 100644 --- a/hassio/api/__init__.py +++ b/hassio/api/__init__.py @@ -48,6 +48,8 @@ class RestAPI(object): self.webapp.router.add_get('/supervisor/ping', api_supervisor.ping) self.webapp.router.add_get('/supervisor/info', api_supervisor.info) + self.webapp.router.add_get( + '/supervisor/addons', api_supervisor.available_addons) self.webapp.router.add_post( '/supervisor/update', api_supervisor.update) self.webapp.router.add_post( diff --git a/hassio/api/supervisor.py b/hassio/api/supervisor.py index 3c09cc99b..c80a92653 100644 --- a/hassio/api/supervisor.py +++ b/hassio/api/supervisor.py @@ -46,9 +46,14 @@ class APISupervisor(object): ATTR_LAST_VERSION: self.config.last_hassio, ATTR_BETA_CHANNEL: self.config.upstream_beta, ATTR_ADDONS: self.addons.list_api, - ATTR_ADDONS_REPOSITORIES: list(self.config.addons_repositories), + ATTR_ADDONS_REPOSITORIES: self.config.addons_repositories, } + @api_process + async def available_addons(self, request): + """Return information for all available addons.""" + return self.addons.list_api + @api_process async def options(self, request): """Set supervisor options.""" diff --git a/hassio/api/util.py b/hassio/api/util.py index 5204e9079..cb5161673 100644 --- a/hassio/api/util.py +++ b/hassio/api/util.py @@ -30,7 +30,7 @@ def api_process(method): except RuntimeError as err: return api_return_error(message=str(err)) - if isinstance(answer, dict): + if isinstance(answer, (dict, list)): return api_return_ok(data=answer) elif answer: return api_return_ok()