Change most references from hassio to ha-addon (#3178)

This commit is contained in:
Jesse Hills 2022-02-09 23:46:20 +13:00 committed by GitHub
parent e7dd6c52ac
commit 5c22065135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 42 additions and 36 deletions

View File

@ -137,7 +137,7 @@ jobs:
--build-type "${{ matrix.build_type }}" \
manifest
deploy-hassio-repo:
deploy-ha-addon-repo:
if: github.repository == 'esphome/esphome' && github.event_name == 'release'
runs-on: ubuntu-latest
needs: [deploy-docker]
@ -150,5 +150,5 @@ jobs:
-u ":$TOKEN" \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/esphome/hassio/actions/workflows/bump-version.yml/dispatches \
https://api.github.com/repos/esphome/home-assistant-addon/actions/workflows/bump-version.yml/dispatches \
-d "{\"ref\":\"main\",\"inputs\":{\"version\":\"$TAG\"}}"

View File

@ -102,7 +102,7 @@ RUN \
ARG BUILD_VERSION=dev
# Copy root filesystem
COPY docker/hassio-rootfs/ /
COPY docker/ha-addon-rootfs/ /
# First install requirements to leverage caching when requirements don't change
COPY requirements.txt requirements_optional.txt docker/platformio_install_deps.py platformio.ini /

View File

@ -10,7 +10,7 @@ server {
ssl_certificate_key /ssl/%%keyfile%%;
# Clear Hass.io Ingress header
proxy_set_header X-Hassio-Ingress "";
proxy_set_header X-HA-Ingress "";
# Redirect http requests to https on the same port.
# https://rageagainstshell.com/2016/11/redirect-http-to-https-on-the-same-port-in-nginx/

View File

@ -4,7 +4,7 @@ server {
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
# Clear Hass.io Ingress header
proxy_set_header X-Hassio-Ingress "";
proxy_set_header X-HA-Ingress "";
location / {
proxy_pass http://esphome;

View File

@ -3,8 +3,8 @@ server {
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
# Set Hass.io Ingress header
proxy_set_header X-Hassio-Ingress "YES";
# Set Home Assistant Ingress header
proxy_set_header X-HA-Ingress "YES";
location / {
# Only allow from Hass.io supervisor

View File

@ -4,7 +4,7 @@
# Runs the ESPHome dashboard
# ==============================================================================
export ESPHOME_IS_HASSIO=true
export ESPHOME_IS_HA_ADDON=true
if bashio::config.true 'leave_front_door_open'; then
export DISABLE_HA_AUTHENTICATION=true
@ -32,4 +32,4 @@ export PLATFORMIO_CACHE_DIR="${pio_cache_base}/cache"
export PLATFORMIO_GLOBALLIB_DIR=/piolibs
bashio::log.info "Starting ESPHome dashboard..."
exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --hassio
exec esphome dashboard /config/esphome --socket /var/run/esphome.sock --ha-addon

View File

@ -661,7 +661,7 @@ def parse_args(argv):
"--open-ui", help="Open the dashboard UI in a browser.", action="store_true"
)
parser_dashboard.add_argument(
"--hassio", help=argparse.SUPPRESS, action="store_true"
"--ha-addon", help=argparse.SUPPRESS, action="store_true"
)
parser_dashboard.add_argument(
"--socket", help="Make the dashboard serve under a unix socket", type=str

View File

@ -20,7 +20,7 @@ from esphome.coroutine import FakeEventLoop as _FakeEventLoop
# pylint: disable=unused-import
from esphome.coroutine import coroutine, coroutine_with_priority # noqa
from esphome.helpers import ensure_unique_string, is_hassio
from esphome.helpers import ensure_unique_string, is_ha_addon
from esphome.util import OrderedDict
if TYPE_CHECKING:
@ -568,12 +568,12 @@ class EsphomeCore:
return self.relative_build_path("src", *path)
def relative_pioenvs_path(self, *path):
if is_hassio():
if is_ha_addon():
return os.path.join("/data", self.name, ".pioenvs", *path)
return self.relative_build_path(".pioenvs", *path)
def relative_piolibdeps_path(self, *path):
if is_hassio():
if is_ha_addon():
return os.path.join("/data", self.name, ".piolibdeps", *path)
return self.relative_build_path(".piolibdeps", *path)

View File

@ -55,13 +55,13 @@ class DashboardSettings:
self.password_hash = ""
self.username = ""
self.using_password = False
self.on_hassio = False
self.on_ha_addon = False
self.cookie_secret = None
def parse_args(self, args):
self.on_hassio = args.hassio
self.on_ha_addon = args.ha_addon
password = args.password or os.getenv("PASSWORD", "")
if not self.on_hassio:
if not self.on_ha_addon:
self.username = args.username or os.getenv("USERNAME", "")
self.using_password = bool(password)
if self.using_password:
@ -77,14 +77,14 @@ class DashboardSettings:
return get_bool_env("ESPHOME_DASHBOARD_USE_PING")
@property
def using_hassio_auth(self):
if not self.on_hassio:
def using_ha_addon_auth(self):
if not self.on_ha_addon:
return False
return not get_bool_env("DISABLE_HA_AUTHENTICATION")
@property
def using_auth(self):
return self.using_password or self.using_hassio_auth
return self.using_password or self.using_ha_addon_auth
def check_password(self, username, password):
if not self.using_auth:
@ -138,10 +138,10 @@ def authenticated(func):
def is_authenticated(request_handler):
if settings.on_hassio:
if settings.on_ha_addon:
# Handle ingress - disable auth on ingress port
# X-Hassio-Ingress is automatically stripped on the non-ingress server in nginx
header = request_handler.request.headers.get("X-Hassio-Ingress", "NO")
# X-HA-Ingress is automatically stripped on the non-ingress server in nginx
header = request_handler.request.headers.get("X-HA-Ingress", "NO")
if str(header) == "YES":
return True
if settings.using_auth:
@ -792,23 +792,23 @@ class LoginHandler(BaseHandler):
self.render(
"login.template.html",
error=error,
hassio=settings.using_hassio_auth,
ha_addon=settings.using_ha_addon_auth,
has_username=bool(settings.username),
**template_args(),
)
def post_hassio_login(self):
def post_ha_addon_login(self):
import requests
headers = {
"X-HASSIO-KEY": os.getenv("HASSIO_TOKEN"),
"Authentication": f"Bearer {os.getenv('SUPERVISOR_TOKEN')}",
}
data = {
"username": self.get_argument("username", ""),
"password": self.get_argument("password", ""),
}
try:
req = requests.post("http://hassio/auth", headers=headers, data=data)
req = requests.post("http://supervisor/auth", headers=headers, data=data)
if req.status_code == 200:
self.set_secure_cookie("authenticated", cookie_authenticated_yes)
self.redirect("/")
@ -835,8 +835,8 @@ class LoginHandler(BaseHandler):
self.render_login_page(error=error_str)
def post(self):
if settings.using_hassio_auth:
self.post_hassio_login()
if settings.using_ha_addon_auth:
self.post_ha_addon_login()
else:
self.post_native_login()

View File

@ -144,8 +144,8 @@ def get_bool_env(var, default=False):
return bool(os.getenv(var, default))
def is_hassio():
return get_bool_env("ESPHOME_IS_HASSIO")
def is_ha_addon():
return get_bool_env("ESPHOME_IS_HA_ADDON")
def walk_files(path):

View File

@ -9,7 +9,7 @@ pyserial==3.5
platformio==5.2.4 # When updating platformio, also update Dockerfile
esptool==3.2
click==8.0.3
esphome-dashboard==20220116.0
esphome-dashboard==20220209.0
aioesphomeapi==10.8.1
zeroconf==0.37.0

View File

@ -222,7 +222,13 @@ def lint_ext_check(fname):
@lint_file_check(
exclude=["**.sh", "docker/hassio-rootfs/**", "docker/*.py", "script/*", "setup.py"]
exclude=[
"**.sh",
"docker/ha-addon-rootfs/**",
"docker/*.py",
"script/*",
"setup.py",
]
)
def lint_executable_bit(fname):
ex = EXECUTABLE_BIT[fname]

View File

@ -124,13 +124,13 @@ def test_get_bool_env(monkeypatch, var, value, default, expected):
@pytest.mark.parametrize("value, expected", ((None, False), ("Yes", True)))
def test_is_hassio(monkeypatch, value, expected):
def test_is_ha_addon(monkeypatch, value, expected):
if value is None:
monkeypatch.delenv("ESPHOME_IS_HASSIO", raising=False)
monkeypatch.delenv("ESPHOME_IS_HA_ADDON", raising=False)
else:
monkeypatch.setenv("ESPHOME_IS_HASSIO", value)
monkeypatch.setenv("ESPHOME_IS_HA_ADDON", value)
actual = helpers.is_hassio()
actual = helpers.is_ha_addon()
assert actual == expected