Compare commits

...

11 Commits
0.4 ... 0.5

Author SHA1 Message Date
pvizeli
820daa4f2b Select Release 0.5 as stable 2017-04-07 11:58:40 +02:00
Pascal Vizeli
fe4e1a1933 Merge pull request #2 from pvizeli/Release-0_5
Release 0.5
2017-04-07 11:19:33 +02:00
pvizeli
8c191e8c98 fix lint 2017-04-07 11:11:26 +02:00
pvizeli
9e95e8671e Add options validation 2017-04-07 11:07:23 +02:00
pvizeli
1ad196424f Fix lint v2 2017-04-07 09:13:08 +02:00
pvizeli
878eb40258 Fix lint 2017-04-07 09:11:05 +02:00
pvizeli
61e133df6b Pump version 2017-04-07 08:58:47 +02:00
pvizeli
23278550be Updates for Release 0.5 2017-04-07 08:57:40 +02:00
Pascal Vizeli
ce01e53806 Update API.md 2017-04-06 21:52:41 +02:00
Pascal Vizeli
716018a26f Update API.md 2017-04-06 21:39:36 +02:00
Pascal Vizeli
912e24229f Update API.md 2017-04-06 21:39:03 +02:00
12 changed files with 73 additions and 29 deletions

2
API.md
View File

@@ -60,6 +60,8 @@ On success
### HassIO
- `/supervisor/ping`
- `/supervisor/info`
```json

View File

@@ -11,6 +11,7 @@ It is a docker image (supervisor) they manage HomeAssistant docker and give a in
- **0.2**: Support for basic HostControll
- **0.3**: Refactor code and add basic rest api
- **0.4**: Move network api code / ssl folder
- **0.5**: Make api compatible to hass component v1
# Hardware Image
The image is based on ResinOS and Yocto Linux. It comes with the HassIO supervisor pre-installed. This includes support to update the supervisor over the air. After flashing your host OS will not require any more maintenance! The image does not include Home Assistant, instead it will downloaded when the image boots up for the first time.

View File

@@ -23,7 +23,7 @@ if __name__ == "__main__":
loop.run_until_complete(hassio.setup())
_LOGGER.info("Start Hassio task")
loop.create_task(hassio.start())
loop.call_soon_threadsafe(asyncio.ensure_future, hassio.start(), loop)
try:
loop.add_signal_handler(
@@ -32,4 +32,5 @@ if __name__ == "__main__":
_LOGGER.warning("Could not bind to SIGTERM")
loop.run_forever()
loop.close()
_LOGGER.info("Close Hassio")

View File

@@ -44,6 +44,7 @@ class RestAPI(object):
"""Register supervisor function."""
api_supervisor = APISupervisor(self.config, self.loop, host_controll)
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/update', api_supervisor.update)
self.webapp.router.add_get(

View File

@@ -2,11 +2,17 @@
import asyncio
import logging
from .util import api_process, json_loads
import voluptuous as vol
from .util import api_process, api_validate
from ..const import ATTR_VERSION, ATTR_CURRENT
_LOGGER = logging.getLogger(__name__)
SCHEMA_VERSION = vol.Schema({
vol.Optional(ATTR_VERSION): vol.Coerce(str),
})
class APIHomeAssistant(object):
"""Handle rest api for homeassistant functions."""
@@ -30,7 +36,7 @@ class APIHomeAssistant(object):
@api_process
async def update(self, request):
"""Update host OS."""
body = await request.json(loads=json_loads)
body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION, self.config.current_homeassistant)
if self.dock_hass.in_progress:

View File

@@ -1,11 +1,19 @@
"""Init file for HassIO host rest api."""
import logging
from .util import api_process_hostcontroll, json_loads
import voluptuous as vol
from .util import api_process_hostcontroll, api_process, api_validate
from ..const import ATTR_VERSION
_LOGGER = logging.getLogger(__name__)
UNKNOWN = 'unknown'
SCHEMA_VERSION = vol.Schema({
vol.Optional(ATTR_VERSION): vol.Coerce(str),
})
class APIHost(object):
"""Handle rest api for host functions."""
@@ -16,10 +24,20 @@ class APIHost(object):
self.loop = loop
self.host_controll = host_controll
@api_process_hostcontroll
def info(self, request):
@api_process
async def info(self, request):
"""Return host information."""
return self.host_controll.info()
if not self.host_controll.active:
info = {
'os': UNKNOWN,
'version': UNKNOWN,
'current': UNKNOWN,
'level': 0,
'hostname': UNKNOWN,
}
return info
return await self.host_controll.info()
@api_process_hostcontroll
def reboot(self, request):
@@ -31,20 +49,10 @@ class APIHost(object):
"""Poweroff host."""
return self.host_controll.shutdown()
@api_process_hostcontroll
def network_info(self, request):
"""Edit network settings."""
pass
@api_process_hostcontroll
def network_update(self, request):
"""Edit network settings."""
pass
@api_process_hostcontroll
async def update(self, request):
"""Update host OS."""
body = await request.json(loads=json_loads)
body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION)
if version == self.host_controll.version:

View File

@@ -1,11 +1,22 @@
"""Init file for HassIO supervisor rest api."""
import logging
from .util import api_process, api_process_hostcontroll, json_loads
import voluptuous as vol
from .util import api_process, api_process_hostcontroll, api_validate
from ..const import ATTR_VERSION, ATTR_CURRENT, ATTR_BETA, HASSIO_VERSION
_LOGGER = logging.getLogger(__name__)
SCHEMA_OPTIONS = vol.Schema({
# pylint: disable=no-value-for-parameter
vol.Optional(ATTR_BETA): vol.Boolean(),
})
SCHEMA_VERSION = vol.Schema({
vol.Optional(ATTR_VERSION): vol.Coerce(str),
})
class APISupervisor(object):
"""Handle rest api for supervisor functions."""
@@ -16,6 +27,11 @@ class APISupervisor(object):
self.loop = loop
self.host_controll = host_controll
@api_process
async def ping(self, request):
"""Return ok for signal that the api is ready."""
return True
@api_process
async def info(self, request):
"""Return host information."""
@@ -30,7 +46,7 @@ class APISupervisor(object):
@api_process
async def options(self, request):
"""Set supervisor options."""
body = await request.json(loads=json_loads)
body = await api_validate(SCHEMA_OPTIONS, request)
if ATTR_BETA in body:
self.config.upstream_beta = body[ATTR_BETA]
@@ -40,7 +56,7 @@ class APISupervisor(object):
@api_process_hostcontroll
async def update(self, request):
"""Update host OS."""
body = await request.json(loads=json_loads)
body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION, self.config.current_hassio)
if version == HASSIO_VERSION:

View File

@@ -4,6 +4,8 @@ import logging
from aiohttp import web
from aiohttp.web_exceptions import HTTPServiceUnavailable
import voluptuous as vol
from voluptuous.humanize import humanize_error
from ..const import (
JSON_RESULT, JSON_DATA, JSON_MESSAGE, RESULT_OK, RESULT_ERROR)
@@ -52,7 +54,7 @@ def api_process_hostcontroll(method):
if isinstance(answer, dict):
return api_return_ok(data=answer)
elif answer is None:
return api_not_supported()
return api_return_error("Function is not supported")
elif answer:
return api_return_ok()
return api_return_error()
@@ -72,10 +74,16 @@ def api_return_ok(data=None):
"""Return a API ok answer."""
return web.json_response({
JSON_RESULT: RESULT_OK,
JSON_DATA: data,
JSON_DATA: data or {},
})
def api_not_supported():
"""Return a api error with not supported."""
return api_return_error("Function is not supported")
async def api_validate(schema, request):
"""Validate request data with schema."""
data = await request.json(loads=json_loads)
try:
schema(data)
except vol.Invalid as ex:
raise RuntimeError(humanize_error(data, ex)) from None
return data

View File

@@ -1,5 +1,5 @@
"""Const file for HassIO."""
HASSIO_VERSION = '0.4'
HASSIO_VERSION = '0.5'
URL_HASSIO_VERSION = \
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'

View File

@@ -36,5 +36,6 @@ setup(
'aiohttp',
'docker',
'colorlog',
'voluptuous',
]
)

View File

@@ -1,5 +1,5 @@
{
"hassio_tag": "0.4",
"hassio_tag": "0.5",
"homeassistant_tag": "0.41",
"resinos_version": "0.3",
"resinhup_version": "0.1"

View File

@@ -1,5 +1,5 @@
{
"hassio_tag": "0.4",
"hassio_tag": "0.5",
"homeassistant_tag": "0.41",
"resinos_version": "0.3",
"resinhup_version": "0.1"