Add system_health to the hassio pre-imports to avoid a late executor job (#112466)

* Add system_health to the hassio pre-imports to avoid a late executor job

`2024-03-05 17:01:33.034 DEBUG (MainThread) [homeassistant.loader] Importing platforms for hassio executor=[system_health] loop=[] took 0.12s`

This one does not take that much time but it happens at a time where
the import executor is the most busy during startup

* key

* move patch as its too early now
This commit is contained in:
J. Nick Koston 2024-03-05 16:31:38 -10:00 committed by GitHub
parent e568f867d2
commit aa216f0298
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 13 deletions

View File

@ -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

View File

@ -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,

View File

@ -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):