diff --git a/hassio_api/hassio/api/__init__.py b/hassio_api/hassio/api/__init__.py index 432f5e9b7..b3fe14dfc 100644 --- a/hassio_api/hassio/api/__init__.py +++ b/hassio_api/hassio/api/__init__.py @@ -22,7 +22,7 @@ class RestAPI(object): self._handler = None self.server = None - def registerHost(self, host_controll): + def register_host(self, host_controll): """Register hostcontroll function.""" api_host = APIHost(self.config, self.loop, host_controll) @@ -35,14 +35,14 @@ class RestAPI(object): self.webapp.router.add_get( '/host/network/update', api_host.network_update) - def registerSupervisor(self, host_controll): + def register_supervisor(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): + def register_homeassistant(self, dock_homeassistant): """Register homeassistant function.""" api_hass = APIHomeAssistant(self.config, self.loop, dock_homeassistant) @@ -57,7 +57,8 @@ class RestAPI(object): self.server = await self.loop.create_server( self._handler, "0.0.0.0", "80") 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): """Stop rest api webserver.""" diff --git a/hassio_api/hassio/api/homeassistant.py b/hassio_api/hassio/api/homeassistant.py index 3feb7f5d5..560628d50 100644 --- a/hassio_api/hassio/api/homeassistant.py +++ b/hassio_api/hassio/api/homeassistant.py @@ -2,7 +2,7 @@ import logging from aiohttp import web -from aiohttp.web_exceptions import HTTPMethodNotAllowed +from aiohttp.web_exceptions import HTTPNotAcceptable from ..const import ATTR_VERSION @@ -16,7 +16,7 @@ class APIHomeAssistant(object): """Initialize homeassistant rest api part.""" self.config = config self.loop = loop - self.dock_hass = hass + self.dock_hass = dock_hass async def info(self, request): """Return host information.""" @@ -26,4 +26,4 @@ class APIHomeAssistant(object): async def update(self, request): """Update host OS.""" - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() diff --git a/hassio_api/hassio/api/host.py b/hassio_api/hassio/api/host.py index 8a665d7bc..0f7926932 100644 --- a/hassio_api/hassio/api/host.py +++ b/hassio_api/hassio/api/host.py @@ -2,7 +2,7 @@ import logging from aiohttp import web -from aiohttp.web_exceptions import HTTPOk, HTTPMethodNotAllowed +from aiohttp.web_exceptions import HTTPOk, HTTPNotAcceptable from ..const import ATTR_VERSION @@ -23,31 +23,31 @@ class APIHost(object): host_info = await self.host_controll.info() if host_info: return web.json_response(host_info) - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() async def reboot(self, request): """Reboot host.""" if await self.host_controll.reboot(): raise HTTPOk() - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() async def shutdown(self, request): """Poweroff host.""" if await self.host_controll.shutdown(): raise HTTPOk() - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() async def network_info(self, request): """Edit network settings.""" - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() async def network_update(self, request): """Edit network settings.""" - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() async def update(self, request): """Update host OS.""" body = await request.json() or {} if await self.host_controll.host_update(body.get(ATTR_VERSION)): raise HTTPOk() - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() diff --git a/hassio_api/hassio/api/supervisor.py b/hassio_api/hassio/api/supervisor.py index 8914db8aa..a4f7cf85a 100644 --- a/hassio_api/hassio/api/supervisor.py +++ b/hassio_api/hassio/api/supervisor.py @@ -2,7 +2,7 @@ import logging 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 @@ -21,7 +21,7 @@ class APISupervisor(object): async def info(self, request): """Return host information.""" return web.json_response({ - ATTR_VERSION: HASSIO_DOCKER, + ATTR_VERSION: HASSIO_VERSION, }) async def update(self, request): @@ -29,4 +29,4 @@ class APISupervisor(object): body = await request.json() or {} if await self.host_controll.supervisor_update(body.get(ATTR_VERSION)): raise HTTPOk() - raise HTTPMethodNotAllowed() + raise HTTPNotAcceptable() diff --git a/hassio_api/hassio/core.py b/hassio_api/hassio/core.py index 05dfebb43..dccf06fca 100644 --- a/hassio_api/hassio/core.py +++ b/hassio_api/hassio/core.py @@ -54,9 +54,9 @@ class HassIO(object): host_info.get('level')) # rest api views - self.api.registerHost(self.host_controll) - self.api.registerSupervisor(self.host_controll) - self.api.registerHomeAssistant(self.homeassistant) + self.api.register_host(self.host_controll) + self.api.register_supervisor(self.host_controll) + self.api.register_homeassistant(self.homeassistant) # first start of supervisor? if self.config.homeassistant_tag is None: diff --git a/hassio_api/hassio/dock/homeassistant.py b/hassio_api/hassio/dock/homeassistant.py index 3ab2d681d..9b7202494 100644 --- a/hassio_api/hassio/dock/homeassistant.py +++ b/hassio_api/hassio/dock/homeassistant.py @@ -46,7 +46,7 @@ class DockerHomeAssistant(DockerBase): }, environment={ 'HASSIO': api_endpoint, - } + }, volumes={ self.config.path_config_docker: {'bind': '/config', 'mode': 'rw'}, diff --git a/hassio_api/hassio/tools.py b/hassio_api/hassio/tools.py index 827d64d3e..95e351ef3 100644 --- a/hassio_api/hassio/tools.py +++ b/hassio_api/hassio/tools.py @@ -40,6 +40,7 @@ def get_version_from_env(env_list): _LOGGER.error("Can't find VERSION in env") return None + def get_local_ip(loop): """Retrieve local IP address.