From 56e8c349c99684d155b7cc695e243c0b2fdf2e4f Mon Sep 17 00:00:00 2001 From: pvizeli Date: Thu, 30 Mar 2017 16:54:25 +0200 Subject: [PATCH] Part 3 of rest api / new files --- hassio_api/hassio/api/homeassistant.py | 29 +++++++++++++++++++++++ hassio_api/hassio/api/supervisor.py | 32 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 hassio_api/hassio/api/homeassistant.py create mode 100644 hassio_api/hassio/api/supervisor.py diff --git a/hassio_api/hassio/api/homeassistant.py b/hassio_api/hassio/api/homeassistant.py new file mode 100644 index 000000000..3feb7f5d5 --- /dev/null +++ b/hassio_api/hassio/api/homeassistant.py @@ -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() diff --git a/hassio_api/hassio/api/supervisor.py b/hassio_api/hassio/api/supervisor.py new file mode 100644 index 000000000..8914db8aa --- /dev/null +++ b/hassio_api/hassio/api/supervisor.py @@ -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()