mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Use supervisor envs instead of hassio (#72601)
This commit is contained in:
parent
c8f677ce4c
commit
3a0111e65d
@ -398,7 +398,7 @@ def _get_domains(hass: core.HomeAssistant, config: dict[str, Any]) -> set[str]:
|
||||
domains.update(hass.config_entries.async_domains())
|
||||
|
||||
# Make sure the Hass.io component is loaded
|
||||
if "HASSIO" in os.environ:
|
||||
if "SUPERVISOR" in os.environ:
|
||||
domains.add("hassio")
|
||||
|
||||
return domains
|
||||
|
@ -505,7 +505,7 @@ def get_supervisor_ip() -> str:
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901
|
||||
"""Set up the Hass.io component."""
|
||||
# Check local setup
|
||||
for env in ("HASSIO", "HASSIO_TOKEN"):
|
||||
for env in ("SUPERVISOR", "SUPERVISOR_TOKEN"):
|
||||
if os.environ.get(env):
|
||||
continue
|
||||
_LOGGER.error("Missing %s environment variable", env)
|
||||
@ -517,7 +517,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
||||
|
||||
async_load_websocket_api(hass)
|
||||
|
||||
host = os.environ["HASSIO"]
|
||||
host = os.environ["SUPERVISOR"]
|
||||
websession = async_get_clientsession(hass)
|
||||
hass.data[DOMAIN] = hassio = HassIO(hass.loop, websession, host)
|
||||
|
||||
|
@ -42,7 +42,7 @@ class HassIOBaseAuth(HomeAssistantView):
|
||||
def _check_access(self, request: web.Request):
|
||||
"""Check if this call is from Supervisor."""
|
||||
# Check caller IP
|
||||
hassio_ip = os.environ["HASSIO"].split(":")[0]
|
||||
hassio_ip = os.environ["SUPERVISOR"].split(":")[0]
|
||||
if ip_address(request.transport.get_extra_info("peername")[0]) != ip_address(
|
||||
hassio_ip
|
||||
):
|
||||
|
@ -246,7 +246,7 @@ class HassIO:
|
||||
method,
|
||||
f"http://{self._ip}{command}",
|
||||
json=payload,
|
||||
headers={X_HASSIO: os.environ.get("HASSIO_TOKEN", "")},
|
||||
headers={X_HASSIO: os.environ.get("SUPERVISOR_TOKEN", "")},
|
||||
timeout=aiohttp.ClientTimeout(total=timeout),
|
||||
)
|
||||
|
||||
|
@ -124,7 +124,7 @@ class HassIOView(HomeAssistantView):
|
||||
def _init_header(request: web.Request) -> dict[str, str]:
|
||||
"""Create initial header."""
|
||||
headers = {
|
||||
X_HASSIO: os.environ.get("HASSIO_TOKEN", ""),
|
||||
X_HASSIO: os.environ.get("SUPERVISOR_TOKEN", ""),
|
||||
CONTENT_TYPE: request.content_type,
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ def _init_header(request: web.Request, token: str) -> CIMultiDict | dict[str, st
|
||||
headers[name] = value
|
||||
|
||||
# Inject token / cleanup later on Supervisor
|
||||
headers[X_HASSIO] = os.environ.get("HASSIO_TOKEN", "")
|
||||
headers[X_HASSIO] = os.environ.get("SUPERVISOR_TOKEN", "")
|
||||
|
||||
# Ingress information
|
||||
headers[X_INGRESS_PATH] = f"/api/hassio_ingress/{token}"
|
||||
|
@ -6,8 +6,8 @@ from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
from . import get_host_info, get_info, get_os_info, get_supervisor_info
|
||||
|
||||
SUPERVISOR_PING = f"http://{os.environ['HASSIO']}/supervisor/ping"
|
||||
OBSERVER_URL = f"http://{os.environ['HASSIO']}:4357"
|
||||
SUPERVISOR_PING = f"http://{os.environ['SUPERVISOR']}/supervisor/ping"
|
||||
OBSERVER_URL = f"http://{os.environ['SUPERVISOR']}:4357"
|
||||
|
||||
|
||||
@callback
|
||||
|
@ -1,2 +1,2 @@
|
||||
"""Tests for Hass.io component."""
|
||||
HASSIO_TOKEN = "123456"
|
||||
SUPERVISOR_TOKEN = "123456"
|
||||
|
@ -9,16 +9,16 @@ from homeassistant.core import CoreState
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import HASSIO_TOKEN
|
||||
from . import SUPERVISOR_TOKEN
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hassio_env():
|
||||
"""Fixture to inject hassio env."""
|
||||
with patch.dict(os.environ, {"HASSIO": "127.0.0.1"}), patch(
|
||||
with patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}), patch(
|
||||
"homeassistant.components.hassio.HassIO.is_connected",
|
||||
return_value={"result": "ok", "data": {}},
|
||||
), patch.dict(os.environ, {"HASSIO_TOKEN": HASSIO_TOKEN}), patch(
|
||||
), patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}), patch(
|
||||
"homeassistant.components.hassio.HassIO.get_info",
|
||||
Mock(side_effect=HassioAPIError()),
|
||||
):
|
||||
@ -75,5 +75,5 @@ def hassio_handler(hass, aioclient_mock):
|
||||
|
||||
websession = hass.loop.run_until_complete(get_client_session())
|
||||
|
||||
with patch.dict(os.environ, {"HASSIO_TOKEN": HASSIO_TOKEN}):
|
||||
with patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}):
|
||||
yield HassIO(hass.loop, websession, "127.0.0.1")
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -13,7 +13,7 @@ from homeassistant.setup import async_setup_component
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@ -336,7 +336,7 @@ async def test_setup_core_push_timezone(hass, aioclient_mock):
|
||||
async def test_setup_hassio_no_additional_data(hass, aioclient_mock):
|
||||
"""Test setup with API push default data."""
|
||||
with patch.dict(os.environ, MOCK_ENVIRON), patch.dict(
|
||||
os.environ, {"HASSIO_TOKEN": "123456"}
|
||||
os.environ, {"SUPERVISOR_TOKEN": "123456"}
|
||||
):
|
||||
result = await async_setup_component(hass, "hassio", {"hassio": {}})
|
||||
assert result
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -12,7 +12,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_ENVIRON = {"HASSIO": "127.0.0.1", "HASSIO_TOKEN": "abcdefgh"}
|
||||
MOCK_ENVIRON = {"SUPERVISOR": "127.0.0.1", "SUPERVISOR_TOKEN": "abcdefgh"}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -33,10 +33,10 @@ BANNED_IPS_WITH_SUPERVISOR = BANNED_IPS + [SUPERVISOR_IP]
|
||||
@pytest.fixture(name="hassio_env")
|
||||
def hassio_env_fixture():
|
||||
"""Fixture to inject hassio env."""
|
||||
with patch.dict(os.environ, {"HASSIO": "127.0.0.1"}), patch(
|
||||
with patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}), patch(
|
||||
"homeassistant.components.hassio.HassIO.is_connected",
|
||||
return_value={"result": "ok", "data": {}},
|
||||
), patch.dict(os.environ, {"HASSIO_TOKEN": "123456"}):
|
||||
), patch.dict(os.environ, {"SUPERVISOR_TOKEN": "123456"}):
|
||||
yield
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ async def mock_supervisor_fixture(hass, aioclient_mock):
|
||||
"""Mock supervisor."""
|
||||
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
|
||||
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
|
||||
with patch.dict(os.environ, {"HASSIO": "127.0.0.1"}), patch(
|
||||
with patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}), patch(
|
||||
"homeassistant.components.hassio.HassIO.is_connected",
|
||||
return_value=True,
|
||||
), patch(
|
||||
@ -79,7 +79,7 @@ async def mock_supervisor_fixture(hass, aioclient_mock):
|
||||
"homeassistant.components.hassio.HassIO.get_ingress_panels",
|
||||
return_value={"panels": {}},
|
||||
), patch.dict(
|
||||
os.environ, {"HASSIO_TOKEN": "123456"}
|
||||
os.environ, {"SUPERVISOR_TOKEN": "123456"}
|
||||
):
|
||||
yield
|
||||
|
||||
|
@ -84,7 +84,7 @@ async def test_load_hassio(hass):
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
assert bootstrap._get_domains(hass, {}) == set()
|
||||
|
||||
with patch.dict(os.environ, {"HASSIO": "1"}):
|
||||
with patch.dict(os.environ, {"SUPERVISOR": "1"}):
|
||||
assert bootstrap._get_domains(hass, {}) == {"hassio"}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user