mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 13:46:31 +00:00
Part 3 of rest api
This commit is contained in:
parent
1d627961f5
commit
ad057352c0
@ -3,8 +3,9 @@ import logging
|
|||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
|
|
||||||
from .homeassistant import APIHomeAssistant
|
|
||||||
from .host import APIHost
|
from .host import APIHost
|
||||||
|
from .supervisor import APISupervisor
|
||||||
|
from .homeassistant import APIHomeAssistant
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -28,12 +29,19 @@ class RestAPI(object):
|
|||||||
self.webapp.router.add_get('/host/info', api_host.info)
|
self.webapp.router.add_get('/host/info', api_host.info)
|
||||||
self.webapp.router.add_get('/host/reboot', api_host.reboot)
|
self.webapp.router.add_get('/host/reboot', api_host.reboot)
|
||||||
self.webapp.router.add_get('/host/shutdown', api_host.shutdown)
|
self.webapp.router.add_get('/host/shutdown', api_host.shutdown)
|
||||||
self.webapp.router.add_get('/host/update', api_host.update_host)
|
self.webapp.router.add_get('/host/update', api_host.update)
|
||||||
self.webapp.router.add_get(
|
self.webapp.router.add_get(
|
||||||
'/host/network/info', api_host.network_info)
|
'/host/network/info', api_host.network_info)
|
||||||
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):
|
||||||
|
"""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 registerHomeAssistant(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)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
"""Init file for HassIO rest api."""
|
"""Init file for HassIO host rest api."""
|
||||||
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, HTTPMethodNotAllowed
|
||||||
|
|
||||||
|
from ..const import ATTR_VERSION
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -11,10 +13,10 @@ class APIHost(object):
|
|||||||
"""Handle rest api for host functions."""
|
"""Handle rest api for host functions."""
|
||||||
|
|
||||||
def __init__(self, config, loop, host_controll):
|
def __init__(self, config, loop, host_controll):
|
||||||
"""Initialize docker base wrapper."""
|
"""Initialize host rest api part."""
|
||||||
self.config = config
|
self.config = config
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self.host_controll
|
self.host_controll = host_controll
|
||||||
|
|
||||||
async def info(self, request):
|
async def info(self, request):
|
||||||
"""Return host information."""
|
"""Return host information."""
|
||||||
@ -43,8 +45,9 @@ class APIHost(object):
|
|||||||
"""Edit network settings."""
|
"""Edit network settings."""
|
||||||
raise HTTPMethodNotAllowed()
|
raise HTTPMethodNotAllowed()
|
||||||
|
|
||||||
async def update_host(self, request):
|
async def update(self, request):
|
||||||
"""Update host OS."""
|
"""Update host OS."""
|
||||||
if await self.host_controll.host_update():
|
body = await request.json() or {}
|
||||||
|
if await self.host_controll.host_update(body.get(ATTR_VERSION)):
|
||||||
raise HTTPOk()
|
raise HTTPOk()
|
||||||
raise HTTPMethodNotAllowed()
|
raise HTTPMethodNotAllowed()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Const file for HassIO."""
|
"""Const file for HassIO."""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
HASSIO_VERSION = '0.3'
|
||||||
|
|
||||||
URL_HASSIO_VERSION = \
|
URL_HASSIO_VERSION = \
|
||||||
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'
|
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'
|
||||||
|
|
||||||
@ -25,3 +27,5 @@ HTTP_PORT = 9123
|
|||||||
|
|
||||||
HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
||||||
HOMEASSISTANT_TAG = 'homeassistant_tag'
|
HOMEASSISTANT_TAG = 'homeassistant_tag'
|
||||||
|
|
||||||
|
ATTR_VERSION = 'version'
|
||||||
|
@ -53,8 +53,9 @@ class HassIO(object):
|
|||||||
host_info.get('version'), host_info.get('hostname'),
|
host_info.get('version'), host_info.get('hostname'),
|
||||||
host_info.get('level'))
|
host_info.get('level'))
|
||||||
|
|
||||||
# api views
|
# rest api views
|
||||||
self.api.registerHost(self.host_controll)
|
self.api.registerHost(self.host_controll)
|
||||||
|
self.api.registerSupervisor(self.host_controll)
|
||||||
self.api.registerHomeAssistant(self.homeassistant)
|
self.api.registerHomeAssistant(self.homeassistant)
|
||||||
|
|
||||||
# first start of supervisor?
|
# first start of supervisor?
|
||||||
|
@ -51,7 +51,7 @@ class HostControll(object):
|
|||||||
data = await reader.readline()
|
data = await reader.readline()
|
||||||
|
|
||||||
response = data.decode()
|
response = data.decode()
|
||||||
_LOGGER.info("Receive from HostControll: %s.", response)
|
_LOGGER.debug("Receive from HostControll: %s.", response)
|
||||||
|
|
||||||
if response == "OK":
|
if response == "OK":
|
||||||
return True
|
return True
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
VERSION = "0.2"
|
from .hassio.const import HASSIO_VERSION
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='HassIO',
|
name='HassIO',
|
||||||
version=VERSION,
|
version=HASSIO_VERSION,
|
||||||
license='BSD License',
|
license='BSD License',
|
||||||
author='The Home Assistant Authors',
|
author='The Home Assistant Authors',
|
||||||
author_email='hello@home-assistant.io',
|
author_email='hello@home-assistant.io',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user