Skip to content

Commit

Permalink
Use supervisor envs instead of hassio (home-assistant#72601)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored May 30, 2022
1 parent c8f677c commit 3a0111e
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, hass: HomeAssistant, user: User) -> None:
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
):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def send_command(
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),
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def _command_proxy(
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,
}

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/hassio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Tests for Hass.io component."""
HASSIO_TOKEN = "123456"
SUPERVISOR_TOKEN = "123456"
8 changes: 4 additions & 4 deletions tests/components/hassio/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
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()),
):
Expand Down Expand Up @@ -75,5 +75,5 @@ async def get_client_session():

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")
2 changes: 1 addition & 1 deletion tests/components/hassio/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/hassio/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
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)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/hassio/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/hassio/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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)
Expand Down
2 changes: 1 addition & 1 deletion tests/components/hassio/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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)
Expand Down
4 changes: 2 additions & 2 deletions tests/components/http/test_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
@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


Expand Down
4 changes: 2 additions & 2 deletions tests/components/onboarding/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}


Expand Down

0 comments on commit 3a0111e

Please sign in to comment.