From 9e4581ac4c7fdc3b9fbfdd8bca38febd08f393b9 Mon Sep 17 00:00:00 2001 From: pvizeli Date: Wed, 5 Apr 2017 08:55:19 +0200 Subject: [PATCH] Update web API for HassIO 0.4 --- hassio_api/README.md | 9 ++++++--- hassio_api/hassio/api/__init__.py | 12 ++++++++---- hassio_api/hassio/api/network.py | 26 ++++++++++++++++++++++++++ hassio_api/hassio/config.py | 6 +++--- hassio_api/hassio/const.py | 2 +- hassio_api/hassio/core.py | 1 + version.json | 2 +- version_beta.json | 4 ++-- 8 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 hassio_api/hassio/api/network.py diff --git a/hassio_api/README.md b/hassio_api/README.md index 43e434d37..28fe3a114 100644 --- a/hassio_api/README.md +++ b/hassio_api/README.md @@ -80,6 +80,8 @@ Payload: {"beta": true|false} - `/host/shutdown` +- `/host/reboot` + - `/host/info` See HostControll info command. @@ -87,12 +89,13 @@ See HostControll info command. - `/host/update` On some device we support host upates. Like ResinOS. -- `/host/network/info` +### Network -- `/host/network/update` +- `/network/info` + +- `/network/options` Payload: {'hostname': '', 'mode': 'dhcp|fixed', 'ssid': '', 'ip': '', 'netmask': '', 'gateway': ''} -- `/host/reboot` ### HomeAssistant diff --git a/hassio_api/hassio/api/__init__.py b/hassio_api/hassio/api/__init__.py index d4f842e33..cde4ae8ef 100644 --- a/hassio_api/hassio/api/__init__.py +++ b/hassio_api/hassio/api/__init__.py @@ -4,6 +4,7 @@ import logging from aiohttp import web from .host import APIHost +from .network import APINetwork from .supervisor import APISupervisor from .homeassistant import APIHomeAssistant @@ -31,10 +32,13 @@ class RestAPI(object): self.webapp.router.add_get('/host/reboot', api_host.reboot) self.webapp.router.add_get('/host/shutdown', api_host.shutdown) self.webapp.router.add_get('/host/update', api_host.update) - self.webapp.router.add_get( - '/host/network/info', api_host.network_info) - self.webapp.router.add_get( - '/host/network/update', api_host.network_update) + + def register_network(self, host_controll): + """Register network function.""" + api_net = APINetwork(self.config, self.loop, host_controll) + + self.webapp.router.add_get('/network/info', api_net.info) + self.webapp.router.add_get('/network/options', api_net.options) def register_supervisor(self, host_controll): """Register supervisor function.""" diff --git a/hassio_api/hassio/api/network.py b/hassio_api/hassio/api/network.py new file mode 100644 index 000000000..39950afcb --- /dev/null +++ b/hassio_api/hassio/api/network.py @@ -0,0 +1,26 @@ +"""Init file for HassIO network rest api.""" +import logging + +from .util import api_process_hostcontroll, json_loads + +_LOGGER = logging.getLogger(__name__) + + +class APINetwork(object): + """Handle rest api for network functions.""" + + def __init__(self, config, loop, host_controll): + """Initialize network rest api part.""" + self.config = config + self.loop = loop + self.host_controll = host_controll + + @api_process_hostcontroll + def info(self, request): + """Show network settings.""" + pass + + @api_process_hostcontroll + def options(self, request): + """Edit network settings.""" + pass diff --git a/hassio_api/hassio/config.py b/hassio_api/hassio/config.py index d7295580c..d710581c5 100644 --- a/hassio_api/hassio/config.py +++ b/hassio_api/hassio/config.py @@ -9,10 +9,10 @@ from .tools import fetch_current_versions _LOGGER = logging.getLogger(__name__) HOMEASSISTANT_CONFIG = "{}/homeassistant_config" -HOMEASSISTANT_SSL = "{}/homeassistant_ssl" HOMEASSISTANT_IMAGE = 'homeassistant_image' HOMEASSISTANT_CURRENT = 'homeassistant_current' +HASSIO_SSL = "{}/ssl" HASSIO_CURRENT = 'hassio_current' UPSTREAM_BETA = 'upstream_beta' @@ -106,9 +106,9 @@ class CoreConfig(object): @property def path_ssl_docker(self): """Return SSL path extern for docker.""" - return HOMEASSISTANT_SSL.format(os.environ['SUPERVISOR_SHARE']) + return HASSIO_SSL.format(os.environ['SUPERVISOR_SHARE']) @property def path_ssl(self): """Return SSL path inside supervisor.""" - return HOMEASSISTANT_SSL.format(HASSIO_SHARE) + return HASSIO_SSL.format(HASSIO_SHARE) diff --git a/hassio_api/hassio/const.py b/hassio_api/hassio/const.py index 3e14616cc..a531b3c68 100644 --- a/hassio_api/hassio/const.py +++ b/hassio_api/hassio/const.py @@ -1,5 +1,5 @@ """Const file for HassIO.""" -HASSIO_VERSION = '0.3' +HASSIO_VERSION = '0.4' URL_HASSIO_VERSION = \ 'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json' diff --git a/hassio_api/hassio/core.py b/hassio_api/hassio/core.py index e8308c33a..0b19eff78 100644 --- a/hassio_api/hassio/core.py +++ b/hassio_api/hassio/core.py @@ -55,6 +55,7 @@ class HassIO(object): # rest api views self.api.register_host(self.host_controll) + self.api.register_network(self.host_controll) self.api.register_supervisor(self.host_controll) self.api.register_homeassistant(self.homeassistant) diff --git a/version.json b/version.json index 34f16f018..21f27e5a5 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "hassio_tag": "0.3", "homeassistant_tag": "0.41", - "resinos_version": "0.2", + "resinos_version": "0.3", "resinhup_version": "0.1" } diff --git a/version_beta.json b/version_beta.json index 34f16f018..834b0974c 100644 --- a/version_beta.json +++ b/version_beta.json @@ -1,6 +1,6 @@ { - "hassio_tag": "0.3", + "hassio_tag": "0.4", "homeassistant_tag": "0.41", - "resinos_version": "0.2", + "resinos_version": "0.3", "resinhup_version": "0.1" }