mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 05:36:29 +00:00
Updates for Release 0.5
This commit is contained in:
parent
ce01e53806
commit
23278550be
@ -23,7 +23,7 @@ if __name__ == "__main__":
|
||||
loop.run_until_complete(hassio.setup())
|
||||
|
||||
_LOGGER.info("Start Hassio task")
|
||||
loop.create_task(hassio.start())
|
||||
loop.call_soon_threadsafe(asyncio.ensure_future, hassio.start(), loop)
|
||||
|
||||
try:
|
||||
loop.add_signal_handler(
|
||||
@ -32,4 +32,5 @@ if __name__ == "__main__":
|
||||
_LOGGER.warning("Could not bind to SIGTERM")
|
||||
|
||||
loop.run_forever()
|
||||
loop.close()
|
||||
_LOGGER.info("Close Hassio")
|
||||
|
@ -44,6 +44,7 @@ class RestAPI(object):
|
||||
"""Register supervisor function."""
|
||||
api_supervisor = APISupervisor(self.config, self.loop, host_controll)
|
||||
|
||||
self.webapp.router.add_get('/supervisor/ping', api_supervisor.ping)
|
||||
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(
|
||||
|
@ -1,11 +1,13 @@
|
||||
"""Init file for HassIO host rest api."""
|
||||
import logging
|
||||
|
||||
from .util import api_process_hostcontroll, json_loads
|
||||
from .util import api_process_hostcontroll, api_process, json_loads
|
||||
from ..const import ATTR_VERSION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
UNKNOWN = 'unknown'
|
||||
|
||||
|
||||
class APIHost(object):
|
||||
"""Handle rest api for host functions."""
|
||||
@ -16,10 +18,20 @@ class APIHost(object):
|
||||
self.loop = loop
|
||||
self.host_controll = host_controll
|
||||
|
||||
@api_process_hostcontroll
|
||||
def info(self, request):
|
||||
@api_process
|
||||
async def info(self, request):
|
||||
"""Return host information."""
|
||||
return self.host_controll.info()
|
||||
if not self.host_controll.active:
|
||||
info = {
|
||||
'os': UNKNOWN,
|
||||
'version': UNKNOWN,
|
||||
'current': UNKNOWN,
|
||||
'level': 0,
|
||||
'hostname': UNKNOWN,
|
||||
}
|
||||
return info
|
||||
|
||||
return await self.host_controll.info()
|
||||
|
||||
@api_process_hostcontroll
|
||||
def reboot(self, request):
|
||||
@ -31,16 +43,6 @@ class APIHost(object):
|
||||
"""Poweroff host."""
|
||||
return self.host_controll.shutdown()
|
||||
|
||||
@api_process_hostcontroll
|
||||
def network_info(self, request):
|
||||
"""Edit network settings."""
|
||||
pass
|
||||
|
||||
@api_process_hostcontroll
|
||||
def network_update(self, request):
|
||||
"""Edit network settings."""
|
||||
pass
|
||||
|
||||
@api_process_hostcontroll
|
||||
async def update(self, request):
|
||||
"""Update host OS."""
|
||||
|
@ -16,6 +16,11 @@ class APISupervisor(object):
|
||||
self.loop = loop
|
||||
self.host_controll = host_controll
|
||||
|
||||
@api_process
|
||||
async def ping(self, request):
|
||||
"""Return ok for signal that the api is ready."""
|
||||
return True
|
||||
|
||||
@api_process
|
||||
async def info(self, request):
|
||||
"""Return host information."""
|
||||
|
@ -52,7 +52,7 @@ def api_process_hostcontroll(method):
|
||||
if isinstance(answer, dict):
|
||||
return api_return_ok(data=answer)
|
||||
elif answer is None:
|
||||
return api_not_supported()
|
||||
return api_return_error("Function is not supported")
|
||||
elif answer:
|
||||
return api_return_ok()
|
||||
return api_return_error()
|
||||
@ -68,14 +68,9 @@ def api_return_error(message=None):
|
||||
})
|
||||
|
||||
|
||||
def api_return_ok(data=None):
|
||||
def api_return_ok(data={}):
|
||||
"""Return a API ok answer."""
|
||||
return web.json_response({
|
||||
JSON_RESULT: RESULT_OK,
|
||||
JSON_DATA: data,
|
||||
})
|
||||
|
||||
|
||||
def api_not_supported():
|
||||
"""Return a api error with not supported."""
|
||||
return api_return_error("Function is not supported")
|
||||
|
Loading…
x
Reference in New Issue
Block a user