Merge pull request #1512 from home-assistant/dev

Release 201
This commit is contained in:
Pascal Vizeli 2020-02-17 11:37:29 +01:00 committed by GitHub
commit 39baea759a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 76 additions and 62 deletions

53
API.md
View File

@ -1,6 +1,6 @@
# Hass.io
# Supervisor
## Hass.io RESTful API
## Supervisor RESTful API
Interface for Home Assistant to control things from supervisor.
@ -22,9 +22,10 @@ On success / Code 200:
}
```
For access to API you need set the `X-HASSIO-KEY` they will be available for Add-ons/HomeAssistant with environment `HASSIO_TOKEN`.
For access to API you need use a authorization header with a `Bearer` token.
They are available for Add-ons and the Home Assistant using the `SUPERVISOR_TOKEN` environment variable.
### Hass.io
### Supervisor
- GET `/supervisor/ping`
@ -285,7 +286,7 @@ return:
### HassOS
- GET `/hassos/info`
- GET `/os/info`
```json
{
@ -298,7 +299,7 @@ return:
}
```
- POST `/hassos/update`
- POST `/os/update`
```json
{
@ -306,7 +307,7 @@ return:
}
```
- POST `/hassos/update/cli`
- POST `/os/update/cli`
```json
{
@ -314,7 +315,7 @@ return:
}
```
- POST `/hassos/config/sync`
- POST `/os/config/sync`
Load host configs from a USB stick.
@ -363,7 +364,7 @@ Trigger an udev reload
### Home Assistant
- GET `/homeassistant/info`
- GET `/core/info`
```json
{
@ -382,7 +383,7 @@ Trigger an udev reload
}
```
- POST `/homeassistant/update`
- POST `/core/update`
Optional:
@ -392,23 +393,23 @@ Optional:
}
```
- GET `/homeassistant/logs`
- GET `/core/logs`
Output is the raw Docker log.
- POST `/homeassistant/restart`
- POST `/homeassistant/check`
- POST `/homeassistant/start`
- POST `/homeassistant/stop`
- POST `/homeassistant/rebuild`
- POST `/core/restart`
- POST `/core/check`
- POST `/core/start`
- POST `/core/stop`
- POST `/core/rebuild`
- POST `/homeassistant/options`
- POST `/core/options`
```json
{
"image": "Optional|null",
"last_version": "Optional for custom image|null",
"port": "port for access hass",
"port": "port for access core",
"ssl": "bool",
"refresh_token": "",
"watchdog": "bool",
@ -418,15 +419,15 @@ Output is the raw Docker log.
Image with `null` and last_version with `null` reset this options.
- POST/GET `/homeassistant/api`
- POST/GET `/core/api`
Proxy to real home-assistant instance.
Proxy to the Home Assistant Core instance.
- GET `/homeassistant/websocket`
- GET `/core/websocket`
Proxy to real websocket instance.
Proxy to Home Assistant Core websocket.
- GET `/homeassistant/stats`
- GET `/core/stats`
```json
{
@ -441,13 +442,13 @@ Proxy to real websocket instance.
}
```
### RESTful for API addons
### RESTful for API add-ons
If an add-on will call itself, you can use `/addons/self/...`.
- GET `/addons`
Get all available addons.
Get all available add-ons.
```json
{
@ -500,7 +501,7 @@ Get all available addons.
"stage": "stable|experimental|deprecated",
"arch": ["armhf", "aarch64", "i386", "amd64"],
"machine": "[raspberrypi2, tinker]",
"homeassistant": "null|min Home Assistant version",
"homeassistant": "null|min Home Assistant Core version",
"repository": "12345678|null",
"version": "null|VERSION_INSTALLED",
"last_version": "LAST_VERSION",

View File

@ -272,11 +272,14 @@ class AddonManager(CoreSysAttributes):
await addon.restore(tar_file)
# Check if new
if slug in self.local:
return
if slug not in self.local:
_LOGGER.info("Detect new Add-on after restore %s", slug)
self.local[slug] = addon
_LOGGER.info("Detect new Add-on after restore %s", slug)
self.local[slug] = addon
# Update ingress
if addon.with_ingress:
with suppress(HomeAssistantAPIError):
await self.sys_ingress.update_hass_panel(addon)
async def repair(self) -> None:
"""Repair local add-ons."""

View File

@ -3,7 +3,7 @@ from enum import Enum
from ipaddress import ip_network
from pathlib import Path
HASSIO_VERSION = "200"
HASSIO_VERSION = "201"
URL_HASSIO_ADDONS = "https://github.com/home-assistant/hassio-addons"

View File

@ -121,6 +121,8 @@ class HassIO(CoreSysAttributes):
):
with suppress(HomeAssistantError):
await self.sys_homeassistant.start()
else:
_LOGGER.info("Skip start of Home Assistant")
# start addon mark as application
await self.sys_addons.boot(STARTUP_APPLICATION)

View File

@ -113,11 +113,6 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
self.version = self.instance.version
self.save_data()
# Fix dns server handling before 194 / Cleanup with version 200
if DNS_SERVERS == self.servers:
self.servers.clear()
self.save_data()
# Start DNS forwarder
self.sys_create_task(self.forwarder.start(self.sys_docker.network.dns))

View File

@ -84,9 +84,10 @@ class HassOS(CoreSysAttributes):
url = URL_HASSOS_OTA.format(version=version, board=self.board)
raucb = Path(self.sys_config.path_tmp, f"hassos-{version}.raucb")
_LOGGER.info("Fetch OTA update from %s", url)
try:
_LOGGER.info("Fetch OTA update from %s", url)
async with self.sys_websession.get(url) as request:
timeout = aiohttp.ClientTimeout(total=600)
async with self.sys_websession.get(url, timeout=timeout) as request:
if request.status != 200:
raise HassOSUpdateError()

View File

@ -330,10 +330,6 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
async def _start(self) -> None:
"""Start Home Assistant Docker & wait."""
if await self.instance.is_running():
_LOGGER.warning("Home Assistant is already running!")
return
# Create new API token
self._data[ATTR_ACCESS_TOKEN] = secrets.token_hex(56)
self.save_data()
@ -347,18 +343,21 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
@process_lock
async def start(self) -> None:
"""Run Home Assistant docker."""
try:
if await self.instance.is_running():
await self.instance.restart()
elif await self.instance.is_initialize():
if await self.instance.is_running():
_LOGGER.warning("Home Assistant is already running!")
return
# Instance/Container exists, simple start
if await self.instance.is_initialize():
try:
await self.instance.start()
else:
await self._start()
return
except DockerAPIError:
raise HomeAssistantError() from None
await self._block_till_run()
except DockerAPIError:
raise HomeAssistantError() from None
# No Instance/Container found, extended start
else:
await self._start()
@process_lock
async def stop(self) -> None:

View File

@ -291,8 +291,8 @@ class SnapshotManager(CoreSysAttributes):
await self.lock.acquire()
async with snapshot:
# Stop Home-Assistant if they will be restored later
if homeassistant and FOLDER_HOMEASSISTANT in folders:
# Stop Home-Assistant for config restore
if FOLDER_HOMEASSISTANT in folders:
await self.sys_homeassistant.stop()
snapshot.restore_homeassistant()

View File

@ -6,7 +6,7 @@ colorlog==4.1.0
cpe==1.2.1
cryptography==2.8
docker==4.2.0
gitpython==3.0.5
gitpython==3.0.7
packaging==20.1
pytz==2019.3
pyudev==0.22.0

View File

@ -67,13 +67,29 @@ function build_supervisor() {
}
function cleanup_lastboot() {
if [[ -f /workspaces/test_supervisor/config.json ]]; then
echo "Cleaning up last boot"
cp /workspaces/test_supervisor/config.json /tmp/config.json
jq -rM 'del(.last_boot)' /tmp/config.json > /workspaces/test_supervisor/config.json
rm /tmp/config.json
fi
}
function cleanup_docker() {
echo "Cleaning up stopped containers..."
docker rm $(docker ps -a -q)
}
function install_cli() {
docker pull homeassistant/amd64-hassio-cli:dev
}
function setup_test_env() {
mkdir -p /workspaces/test_hassio
mkdir -p /workspaces/test_supervisor
echo "Start Supervisor"
docker run --rm --privileged \
@ -82,9 +98,9 @@ function setup_test_env() {
--security-opt apparmor:unconfined \
-v /run/docker.sock:/run/docker.sock \
-v /run/dbus:/run/dbus \
-v "/workspaces/test_hassio":/data \
-v "/workspaces/test_supervisor":/data \
-v /etc/machine-id:/etc/machine-id:ro \
-e SUPERVISOR_SHARE="/workspaces/test_hassio" \
-e SUPERVISOR_SHARE="/workspaces/test_supervisor" \
-e SUPERVISOR_NAME=hassio_supervisor \
-e SUPERVISOR_DEV=1 \
-e HOMEASSISTANT_REPOSITORY="homeassistant/qemux86-64-homeassistant" \
@ -97,12 +113,9 @@ echo "Start Test-Env"
start_docker
trap "stop_docker" ERR
# Clean homeassistant instance
if docker rm -f homeassistant 2> /dev/null; then
echo "Cleanup HomeAssistant instance"
fi
build_supervisor
install_cli
cleanup_lastboot
cleanup_docker
setup_test_env
stop_docker