Part 3 of rest api / new files

This commit is contained in:
pvizeli 2017-03-30 16:54:25 +02:00
parent ad057352c0
commit 56e8c349c9
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,29 @@
"""Init file for HassIO homeassistant rest api."""
import logging
from aiohttp import web
from aiohttp.web_exceptions import HTTPMethodNotAllowed
from ..const import ATTR_VERSION
_LOGGER = logging.getLogger(__name__)
class APIHomeAssistant(object):
"""Handle rest api for homeassistant functions."""
def __init__(self, config, loop, dock_hass):
"""Initialize homeassistant rest api part."""
self.config = config
self.loop = loop
self.dock_hass = hass
async def info(self, request):
"""Return host information."""
return web.json_response({
ATTR_VERSION: self.dock_hass.version,
})
async def update(self, request):
"""Update host OS."""
raise HTTPMethodNotAllowed()

View File

@ -0,0 +1,32 @@
"""Init file for HassIO supervisor rest api."""
import logging
from aiohttp import web
from aiohttp.web_exceptions import HTTPOk, HTTPMethodNotAllowed
from ..const import ATTR_VERSION, HASSIO_VERSION
_LOGGER = logging.getLogger(__name__)
class APISupervisor(object):
"""Handle rest api for supervisor functions."""
def __init__(self, config, loop, host_controll):
"""Initialize supervisor rest api part."""
self.config = config
self.loop = loop
self.host_controll = host_controll
async def info(self, request):
"""Return host information."""
return web.json_response({
ATTR_VERSION: HASSIO_DOCKER,
})
async def update(self, request):
"""Update host OS."""
body = await request.json() or {}
if await self.host_controll.supervisor_update(body.get(ATTR_VERSION)):
raise HTTPOk()
raise HTTPMethodNotAllowed()