This commit is contained in:
pvizeli 2017-03-30 18:02:32 +02:00
parent 7437480379
commit ce920d3e5e
7 changed files with 23 additions and 21 deletions

View File

@ -22,7 +22,7 @@ class RestAPI(object):
self._handler = None self._handler = None
self.server = None self.server = None
def registerHost(self, host_controll): def register_host(self, host_controll):
"""Register hostcontroll function.""" """Register hostcontroll function."""
api_host = APIHost(self.config, self.loop, host_controll) api_host = APIHost(self.config, self.loop, host_controll)
@ -35,14 +35,14 @@ class RestAPI(object):
self.webapp.router.add_get( self.webapp.router.add_get(
'/host/network/update', api_host.network_update) '/host/network/update', api_host.network_update)
def registerSupervisor(self, host_controll): def register_supervisor(self, host_controll):
"""Register supervisor function.""" """Register supervisor function."""
api_supervisor = APISupervisor(self.config, self.loop, host_controll) 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/info', api_supervisor.info)
self.webapp.router.add_get('/supervisor/update', api_supervisor.update) self.webapp.router.add_get('/supervisor/update', api_supervisor.update)
def registerHomeAssistant(self, dock_homeassistant): def register_homeassistant(self, dock_homeassistant):
"""Register homeassistant function.""" """Register homeassistant function."""
api_hass = APIHomeAssistant(self.config, self.loop, dock_homeassistant) api_hass = APIHomeAssistant(self.config, self.loop, dock_homeassistant)
@ -57,7 +57,8 @@ class RestAPI(object):
self.server = await self.loop.create_server( self.server = await self.loop.create_server(
self._handler, "0.0.0.0", "80") self._handler, "0.0.0.0", "80")
except OSError as err: except OSError as err:
_LOGGER.fatal("Failed to create HTTP server at 0.0.0.0:80") _LOGGER.fatal(
"Failed to create HTTP server at 0.0.0.0:80 -> %s", err)
async def stop(self): async def stop(self):
"""Stop rest api webserver.""" """Stop rest api webserver."""

View File

@ -2,7 +2,7 @@
import logging import logging
from aiohttp import web from aiohttp import web
from aiohttp.web_exceptions import HTTPMethodNotAllowed from aiohttp.web_exceptions import HTTPNotAcceptable
from ..const import ATTR_VERSION from ..const import ATTR_VERSION
@ -16,7 +16,7 @@ class APIHomeAssistant(object):
"""Initialize homeassistant rest api part.""" """Initialize homeassistant rest api part."""
self.config = config self.config = config
self.loop = loop self.loop = loop
self.dock_hass = hass self.dock_hass = dock_hass
async def info(self, request): async def info(self, request):
"""Return host information.""" """Return host information."""
@ -26,4 +26,4 @@ class APIHomeAssistant(object):
async def update(self, request): async def update(self, request):
"""Update host OS.""" """Update host OS."""
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()

View File

@ -2,7 +2,7 @@
import logging import logging
from aiohttp import web from aiohttp import web
from aiohttp.web_exceptions import HTTPOk, HTTPMethodNotAllowed from aiohttp.web_exceptions import HTTPOk, HTTPNotAcceptable
from ..const import ATTR_VERSION from ..const import ATTR_VERSION
@ -23,31 +23,31 @@ class APIHost(object):
host_info = await self.host_controll.info() host_info = await self.host_controll.info()
if host_info: if host_info:
return web.json_response(host_info) return web.json_response(host_info)
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()
async def reboot(self, request): async def reboot(self, request):
"""Reboot host.""" """Reboot host."""
if await self.host_controll.reboot(): if await self.host_controll.reboot():
raise HTTPOk() raise HTTPOk()
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()
async def shutdown(self, request): async def shutdown(self, request):
"""Poweroff host.""" """Poweroff host."""
if await self.host_controll.shutdown(): if await self.host_controll.shutdown():
raise HTTPOk() raise HTTPOk()
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()
async def network_info(self, request): async def network_info(self, request):
"""Edit network settings.""" """Edit network settings."""
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()
async def network_update(self, request): async def network_update(self, request):
"""Edit network settings.""" """Edit network settings."""
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()
async def update(self, request): async def update(self, request):
"""Update host OS.""" """Update host OS."""
body = await request.json() or {} body = await request.json() or {}
if await self.host_controll.host_update(body.get(ATTR_VERSION)): if await self.host_controll.host_update(body.get(ATTR_VERSION)):
raise HTTPOk() raise HTTPOk()
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()

View File

@ -2,7 +2,7 @@
import logging import logging
from aiohttp import web from aiohttp import web
from aiohttp.web_exceptions import HTTPOk, HTTPMethodNotAllowed from aiohttp.web_exceptions import HTTPOk, HTTPNotAcceptable
from ..const import ATTR_VERSION, HASSIO_VERSION from ..const import ATTR_VERSION, HASSIO_VERSION
@ -21,7 +21,7 @@ class APISupervisor(object):
async def info(self, request): async def info(self, request):
"""Return host information.""" """Return host information."""
return web.json_response({ return web.json_response({
ATTR_VERSION: HASSIO_DOCKER, ATTR_VERSION: HASSIO_VERSION,
}) })
async def update(self, request): async def update(self, request):
@ -29,4 +29,4 @@ class APISupervisor(object):
body = await request.json() or {} body = await request.json() or {}
if await self.host_controll.supervisor_update(body.get(ATTR_VERSION)): if await self.host_controll.supervisor_update(body.get(ATTR_VERSION)):
raise HTTPOk() raise HTTPOk()
raise HTTPMethodNotAllowed() raise HTTPNotAcceptable()

View File

@ -54,9 +54,9 @@ class HassIO(object):
host_info.get('level')) host_info.get('level'))
# rest api views # rest api views
self.api.registerHost(self.host_controll) self.api.register_host(self.host_controll)
self.api.registerSupervisor(self.host_controll) self.api.register_supervisor(self.host_controll)
self.api.registerHomeAssistant(self.homeassistant) self.api.register_homeassistant(self.homeassistant)
# first start of supervisor? # first start of supervisor?
if self.config.homeassistant_tag is None: if self.config.homeassistant_tag is None:

View File

@ -46,7 +46,7 @@ class DockerHomeAssistant(DockerBase):
}, },
environment={ environment={
'HASSIO': api_endpoint, 'HASSIO': api_endpoint,
} },
volumes={ volumes={
self.config.path_config_docker: self.config.path_config_docker:
{'bind': '/config', 'mode': 'rw'}, {'bind': '/config', 'mode': 'rw'},

View File

@ -40,6 +40,7 @@ def get_version_from_env(env_list):
_LOGGER.error("Can't find VERSION in env") _LOGGER.error("Can't find VERSION in env")
return None return None
def get_local_ip(loop): def get_local_ip(loop):
"""Retrieve local IP address. """Retrieve local IP address.