diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index cd1c6e735ef..1a666fcc42d 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -43,10 +43,17 @@ from homeassistant.loader import bind_hass from homeassistant.util.async_ import create_eager_task from homeassistant.util.dt import now -# config_flow, diagnostics, and entity platforms are imported to ensure -# other dependencies that wait for hassio are not waiting +# config_flow, diagnostics, system_health, and entity platforms are imported to +# ensure other dependencies that wait for hassio are not waiting # for hassio to import its platforms -from . import binary_sensor, config_flow, diagnostics, sensor, update # noqa: F401 +from . import ( # noqa: F401 + binary_sensor, + config_flow, + diagnostics, + sensor, + system_health, + update, +) from .addon_manager import AddonError, AddonInfo, AddonManager, AddonState # noqa: F401 from .addon_panel import async_setup_addon_panel from .auth import async_setup_auth_view diff --git a/homeassistant/components/hassio/system_health.py b/homeassistant/components/hassio/system_health.py index d89224a2476..e46db2f8e75 100644 --- a/homeassistant/components/hassio/system_health.py +++ b/homeassistant/components/hassio/system_health.py @@ -7,10 +7,10 @@ from typing import Any from homeassistant.components import system_health from homeassistant.core import HomeAssistant, callback -from . import get_host_info, get_info, get_os_info, get_supervisor_info +from .data import get_host_info, get_info, get_os_info, get_supervisor_info -SUPERVISOR_PING = f"http://{os.environ['SUPERVISOR']}/supervisor/ping" -OBSERVER_URL = f"http://{os.environ['SUPERVISOR']}:4357" +SUPERVISOR_PING = "http://{ip_address}/supervisor/ping" +OBSERVER_URL = "http://{ip_address}:4357" @callback @@ -23,6 +23,7 @@ def async_register( async def system_health_info(hass: HomeAssistant) -> dict[str, Any]: """Get info for the info page.""" + ip_address = os.environ["SUPERVISOR"] info = get_info(hass) or {} host_info = get_host_info(hass) or {} supervisor_info = get_supervisor_info(hass) @@ -62,7 +63,9 @@ async def system_health_info(hass: HomeAssistant) -> dict[str, Any]: information["board"] = os_info.get("board") information["supervisor_api"] = system_health.async_check_can_reach_url( - hass, SUPERVISOR_PING, OBSERVER_URL + hass, + SUPERVISOR_PING.format(ip_address=ip_address), + OBSERVER_URL.format(ip_address=ip_address), ) information["version_api"] = system_health.async_check_can_reach_url( hass, diff --git a/tests/components/hassio/test_system_health.py b/tests/components/hassio/test_system_health.py index 7a01c9444ab..715bf3bab91 100644 --- a/tests/components/hassio/test_system_health.py +++ b/tests/components/hassio/test_system_health.py @@ -28,8 +28,7 @@ async def test_hassio_system_health( ) hass.config.components.add("hassio") - with patch.dict(os.environ, MOCK_ENVIRON): - assert await async_setup_component(hass, "system_health", {}) + assert await async_setup_component(hass, "system_health", {}) hass.data["hassio_info"] = { "channel": "stable", @@ -50,7 +49,8 @@ async def test_hassio_system_health( "addons": [{"name": "Awesome Addon", "version": "1.0.0"}], } - info = await get_system_health_info(hass, "hassio") + with patch.dict(os.environ, MOCK_ENVIRON): + info = await get_system_health_info(hass, "hassio") for key, val in info.items(): if asyncio.iscoroutine(val): @@ -87,8 +87,7 @@ async def test_hassio_system_health_with_issues( ) hass.config.components.add("hassio") - with patch.dict(os.environ, MOCK_ENVIRON): - assert await async_setup_component(hass, "system_health", {}) + assert await async_setup_component(hass, "system_health", {}) hass.data["hassio_info"] = {"channel": "stable"} hass.data["hassio_host_info"] = {} @@ -98,7 +97,8 @@ async def test_hassio_system_health_with_issues( "supported": False, } - info = await get_system_health_info(hass, "hassio") + with patch.dict(os.environ, MOCK_ENVIRON): + info = await get_system_health_info(hass, "hassio") for key, val in info.items(): if asyncio.iscoroutine(val):