Part 3 of rest api

This commit is contained in:
pvizeli 2017-03-30 16:54:13 +02:00
parent 1d627961f5
commit ad057352c0
6 changed files with 28 additions and 11 deletions

View File

@ -3,8 +3,9 @@ import logging
from aiohttp import web
from .homeassistant import APIHomeAssistant
from .host import APIHost
from .supervisor import APISupervisor
from .homeassistant import APIHomeAssistant
_LOGGER = logging.getLogger(__name__)
@ -28,12 +29,19 @@ class RestAPI(object):
self.webapp.router.add_get('/host/info', api_host.info)
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_host)
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 registerSupervisor(self, host_controll):
"""Register supervisor function."""
api_supervisor = APISupervisor(self.config, self.loop, host_controll)
self.webapp.router.add_get('/supervisor/info', api_supervisor.info)
self.webapp.router.add_get('/supervisor/update', api_supervisor.update)
def registerHomeAssistant(self, dock_homeassistant):
"""Register homeassistant function."""
api_hass = APIHomeAssistant(self.config, self.loop, dock_homeassistant)

View File

@ -1,9 +1,11 @@
"""Init file for HassIO rest api."""
"""Init file for HassIO host rest api."""
import logging
from aiohttp import web
from aiohttp.web_exceptions import HTTPOk, HTTPMethodNotAllowed
from ..const import ATTR_VERSION
_LOGGER = logging.getLogger(__name__)
@ -11,10 +13,10 @@ class APIHost(object):
"""Handle rest api for host functions."""
def __init__(self, config, loop, host_controll):
"""Initialize docker base wrapper."""
"""Initialize host rest api part."""
self.config = config
self.loop = loop
self.host_controll
self.host_controll = host_controll
async def info(self, request):
"""Return host information."""
@ -43,8 +45,9 @@ class APIHost(object):
"""Edit network settings."""
raise HTTPMethodNotAllowed()
async def update_host(self, request):
async def update(self, request):
"""Update host OS."""
if await self.host_controll.host_update():
body = await request.json() or {}
if await self.host_controll.host_update(body.get(ATTR_VERSION)):
raise HTTPOk()
raise HTTPMethodNotAllowed()

View File

@ -1,6 +1,8 @@
"""Const file for HassIO."""
import os
HASSIO_VERSION = '0.3'
URL_HASSIO_VERSION = \
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'
@ -25,3 +27,5 @@ HTTP_PORT = 9123
HOMEASSISTANT_IMAGE = 'homeassistant_image'
HOMEASSISTANT_TAG = 'homeassistant_tag'
ATTR_VERSION = 'version'

View File

@ -53,8 +53,9 @@ class HassIO(object):
host_info.get('version'), host_info.get('hostname'),
host_info.get('level'))
# api views
# rest api views
self.api.registerHost(self.host_controll)
self.api.registerSupervisor(self.host_controll)
self.api.registerHomeAssistant(self.homeassistant)
# first start of supervisor?

View File

@ -51,7 +51,7 @@ class HostControll(object):
data = await reader.readline()
response = data.decode()
_LOGGER.info("Receive from HostControll: %s.", response)
_LOGGER.debug("Receive from HostControll: %s.", response)
if response == "OK":
return True

View File

@ -1,10 +1,11 @@
from setuptools import setup
VERSION = "0.2"
from .hassio.const import HASSIO_VERSION
setup(
name='HassIO',
version=VERSION,
version=HASSIO_VERSION,
license='BSD License',
author='The Home Assistant Authors',
author_email='hello@home-assistant.io',