From ddb8eef4d12e1eadb6c59af27151a75fb5b2cd14 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sun, 9 Feb 2020 22:41:22 +0100 Subject: [PATCH 1/8] Pump version to 201 --- hassio/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/const.py b/hassio/const.py index f12e00c61..f840b61d5 100644 --- a/hassio/const.py +++ b/hassio/const.py @@ -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" From 5bee1d851cfa85057433ce6aa99bd23a4af56ed5 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2020 16:08:56 +0100 Subject: [PATCH 2/8] Bump gitpython from 3.0.5 to 3.0.7 (#1497) Bumps [gitpython](https://github.com/gitpython-developers/GitPython) from 3.0.5 to 3.0.7. - [Release notes](https://github.com/gitpython-developers/GitPython/releases) - [Changelog](https://github.com/gitpython-developers/GitPython/blob/master/CHANGES) - [Commits](https://github.com/gitpython-developers/GitPython/compare/3.0.5...3.0.7) Signed-off-by: dependabot-preview[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3a7917b29..4955fb836 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 From d78689554a604c1ec4854d08463093f15b3a66df Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Mon, 10 Feb 2020 23:52:22 +0100 Subject: [PATCH 3/8] Cleanup old logic (#1500) --- hassio/dns.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hassio/dns.py b/hassio/dns.py index b32ad834f..306daacc6 100644 --- a/hassio/dns.py +++ b/hassio/dns.py @@ -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)) From aa1f08fe8ac7ee03a1c074de99069124080cfd00 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 11 Feb 2020 23:09:23 +0100 Subject: [PATCH 4/8] Update API docs to reflect latest changes (#1502) --- API.md | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/API.md b/API.md index d90abace3..0a1fbd328 100644 --- a/API.md +++ b/API.md @@ -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", From c33d31996d55adbeb6f951ef20ec77c7c5e7212b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 13 Feb 2020 17:25:37 +0100 Subject: [PATCH 5/8] Set timeout of 10min for download OTA (#1505) --- hassio/hassos.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hassio/hassos.py b/hassio/hassos.py index f2401450e..1e3b110c5 100644 --- a/hassio/hassos.py +++ b/hassio/hassos.py @@ -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() From 9e5c276e3b985d463647256d1c5feef2160ba8c6 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 14 Feb 2020 15:25:43 +0100 Subject: [PATCH 6/8] Home Assistant Core start flow / partial restore (#1507) * Fix start flow logic * Add a note * Fix flow on partial restore --- hassio/core.py | 2 ++ hassio/homeassistant.py | 25 ++++++++++++------------- hassio/snapshots/__init__.py | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hassio/core.py b/hassio/core.py index beaec91ad..ae557ae60 100644 --- a/hassio/core.py +++ b/hassio/core.py @@ -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) diff --git a/hassio/homeassistant.py b/hassio/homeassistant.py index cbfd8f34f..463dcc4ff 100644 --- a/hassio/homeassistant.py +++ b/hassio/homeassistant.py @@ -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: diff --git a/hassio/snapshots/__init__.py b/hassio/snapshots/__init__.py index 9595df19e..42b14cf56 100644 --- a/hassio/snapshots/__init__.py +++ b/hassio/snapshots/__init__.py @@ -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() From e24987a610a50d961e4579699a00b19e9755097b Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 14 Feb 2020 15:58:26 +0100 Subject: [PATCH 7/8] Fix ingress on panel after restore (#1508) * Fix ingress on panel after restore * Supress errors --- hassio/addons/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hassio/addons/__init__.py b/hassio/addons/__init__.py index ce75fc408..3e2a18eb6 100644 --- a/hassio/addons/__init__.py +++ b/hassio/addons/__init__.py @@ -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.""" From 80ddb1d262d1e458d1d5355deebe6ab4ed985ed3 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Fri, 14 Feb 2020 17:05:03 +0000 Subject: [PATCH 8/8] Fix startup of dev envoirement --- scripts/test_env.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/test_env.sh b/scripts/test_env.sh index 3760f3ddb..c40df18a9 100755 --- a/scripts/test_env.sh +++ b/scripts/test_env.sh @@ -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