mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 12:46:32 +00:00
Add beta upstream
This commit is contained in:
parent
0964d95c41
commit
23ba1b64a5
@ -70,9 +70,12 @@ On success
|
||||
```
|
||||
|
||||
- `/supervisor/update`
|
||||
Payload: {'version': '0.XX'}
|
||||
Payload: {"version": "0.XX"}
|
||||
If version is None it read last version from server.
|
||||
|
||||
- `/supervisor/option`
|
||||
Payload: {"beta": true|false}
|
||||
|
||||
### Host
|
||||
|
||||
- `/host/shutdown`
|
||||
@ -103,7 +106,7 @@ Payload: {'hostname': '', 'mode': 'dhcp|fixed', 'ssid': '', 'ip': '', 'netmask':
|
||||
```
|
||||
|
||||
- `/homeassistant/update`
|
||||
Payload: {'version': '0.XX.Y'}
|
||||
Payload: {"version": "0.XX.Y"}
|
||||
If version is None it read last version from server.
|
||||
|
||||
### REST API addons
|
||||
@ -118,10 +121,10 @@ Payload: {'options': {}}
|
||||
- `/addons/{addon}/stop`
|
||||
|
||||
- `/addons/{addon}/install`
|
||||
Payload: {'version': 'x.x'}
|
||||
Payload: {"version": "x.x"}
|
||||
|
||||
- `/addons/{addon}/uninstall`
|
||||
|
||||
- `/addons/{addon}/update`
|
||||
Payload: {'version': 'x.x'}
|
||||
Payload: {"version": "x.x"}
|
||||
If version is None it read last version from server.
|
||||
|
@ -42,6 +42,8 @@ class RestAPI(object):
|
||||
|
||||
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/options', api_supervisor.options)
|
||||
|
||||
def register_homeassistant(self, dock_homeassistant):
|
||||
"""Register homeassistant function."""
|
||||
|
@ -2,7 +2,7 @@
|
||||
import logging
|
||||
|
||||
from .util import api_process, api_process_hostcontroll, json_loads
|
||||
from ..const import ATTR_VERSION, ATTR_CURRENT, HASSIO_VERSION
|
||||
from ..const import ATTR_VERSION, ATTR_CURRENT, ATTR_BETA, HASSIO_VERSION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -22,10 +22,22 @@ class APISupervisor(object):
|
||||
info = {
|
||||
ATTR_VERSION: HASSIO_VERSION,
|
||||
ATTR_CURRENT: self.config.current_hassio,
|
||||
ATTR_BETA: self.config.upstream_beta,
|
||||
}
|
||||
|
||||
return info
|
||||
|
||||
@api_process
|
||||
async def options(self, request):
|
||||
"""Set supervisor options."""
|
||||
update = False
|
||||
body = await request.json(loads=json_loads)
|
||||
|
||||
if ATTR_BETA in body:
|
||||
self.config.upstream_beta = body[ATTR_BETA]
|
||||
|
||||
return self.config.save()
|
||||
|
||||
@api_process_hostcontroll
|
||||
async def update(self, request):
|
||||
"""Update host OS."""
|
||||
|
@ -14,6 +14,7 @@ HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
||||
HOMEASSISTANT_CURRENT = 'homeassistant_current'
|
||||
|
||||
HASSIO_CURRENT = 'hassio_current'
|
||||
UPSTREAM_BETA = 'upstream_beta'
|
||||
|
||||
|
||||
class CoreConfig(object):
|
||||
@ -37,7 +38,9 @@ class CoreConfig(object):
|
||||
if not self._data:
|
||||
self._data.update({
|
||||
HOMEASSISTANT_IMAGE: os.environ['HOMEASSISTANT_REPOSITORY'],
|
||||
UPSTREAM_BETA: False,
|
||||
})
|
||||
self.save()
|
||||
|
||||
def save(self):
|
||||
"""Store data to config file."""
|
||||
@ -46,10 +49,14 @@ class CoreConfig(object):
|
||||
conf_file.write(json.dumps(self._data))
|
||||
except OSError:
|
||||
_LOGGER.exception("Can't store config in %s", self._filename)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def fetch_update_infos(self):
|
||||
"""Read current versions from web."""
|
||||
current = await fetch_current_versions(self.websession)
|
||||
current = await fetch_current_versions(
|
||||
self.websession, beta=self.upstream_beta)
|
||||
|
||||
if current:
|
||||
self._data.update({
|
||||
@ -61,6 +68,16 @@ class CoreConfig(object):
|
||||
|
||||
return False
|
||||
|
||||
@property
|
||||
def upstream_beta(self):
|
||||
"""Return True if we run in beta upstream."""
|
||||
return self._data.get(UPSTREAM_BETA, False)
|
||||
|
||||
@upstream_beta.setter
|
||||
def upstream_beta(self, value):
|
||||
"""Set beta upstream mode."""
|
||||
self._data[UPSTREAM_BETA] = bool(value)
|
||||
|
||||
@property
|
||||
def homeassistant_image(self):
|
||||
"""Return docker homeassistant repository."""
|
||||
|
@ -3,6 +3,8 @@ HASSIO_VERSION = '0.3'
|
||||
|
||||
URL_HASSIO_VERSION = \
|
||||
'https://raw.githubusercontent.com/pvizeli/hassio/master/version.json'
|
||||
URL_HASSIO_VERSION_BETA = \
|
||||
'https://raw.githubusercontent.com/pvizeli/hassio/master/version_beta.json'
|
||||
|
||||
URL_ADDONS_REPO = 'https://github.com/pvizeli/hassio-addons'
|
||||
|
||||
@ -25,3 +27,4 @@ RESULT_OK = 'ok'
|
||||
|
||||
ATTR_VERSION = 'version'
|
||||
ATTR_CURRENT = 'current'
|
||||
ATTR_BETA = 'beta'
|
||||
|
@ -7,25 +7,26 @@ import socket
|
||||
import aiohttp
|
||||
import async_timeout
|
||||
|
||||
from .const import URL_HASSIO_VERSION
|
||||
from .const import URL_HASSIO_VERSION, URL_HASSIO_VERSION_BETA
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_RE_VERSION = re.compile(r"VERSION=(.*)")
|
||||
|
||||
|
||||
async def fetch_current_versions(websession):
|
||||
async def fetch_current_versions(websession, beta=False):
|
||||
"""Fetch current versions from github.
|
||||
|
||||
Is a coroutine.
|
||||
"""
|
||||
url = URL_HASSIO_VERSION_BETA if beta or URL_HASSIO_VERSION
|
||||
try:
|
||||
with async_timeout.timeout(10, loop=websession.loop):
|
||||
async with websession.get(URL_HASSIO_VERSION) as request:
|
||||
async with websession.get(url) as request:
|
||||
return await request.json(content_type=None)
|
||||
|
||||
except (ValueError, aiohttp.ClientError, asyncio.TimeoutError) as err:
|
||||
_LOGGER.warning("Can't fetch versions from github! %s", err)
|
||||
_LOGGER.warning("Can't fetch versions from %s! %s", url, err)
|
||||
|
||||
|
||||
def get_version_from_env(env_list):
|
||||
|
Loading…
x
Reference in New Issue
Block a user