mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Fix system_info importing hassio in the event loop (#113903)
This commit is contained in:
parent
ac175a4240
commit
267fe3dc34
@ -7,13 +7,15 @@ from getpass import getuser
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from homeassistant.const import __version__ as current_version
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.util.package import is_docker_env, is_virtual_env
|
||||
|
||||
from .importlib import async_import_module
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -32,8 +34,14 @@ cached_get_user = cache(getuser)
|
||||
async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
||||
"""Return info about the system."""
|
||||
# Local import to avoid circular dependencies
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from homeassistant.components import hassio
|
||||
# We use the import helper because hassio
|
||||
# may not be loaded yet and we don't want to
|
||||
# do blocking I/O in the event loop to import it.
|
||||
if TYPE_CHECKING:
|
||||
# pylint: disable-next=import-outside-toplevel
|
||||
from homeassistant.components import hassio
|
||||
else:
|
||||
hassio = await async_import_module(hass, "homeassistant.components.hassio")
|
||||
|
||||
is_hassio = hassio.is_hassio(hass)
|
||||
|
||||
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import hassio
|
||||
from homeassistant.const import __version__ as current_version
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.system_info import async_get_system_info, is_official_image
|
||||
@ -39,8 +40,8 @@ async def test_get_system_info_supervisor_not_available(
|
||||
"homeassistant.helpers.system_info.is_docker_env", return_value=True
|
||||
), patch(
|
||||
"homeassistant.helpers.system_info.is_official_image", return_value=True
|
||||
), patch("homeassistant.components.hassio.is_hassio", return_value=True), patch(
|
||||
"homeassistant.components.hassio.get_info", return_value=None
|
||||
), patch.object(hassio, "is_hassio", return_value=True), patch.object(
|
||||
hassio, "get_info", return_value=None
|
||||
), patch("homeassistant.helpers.system_info.cached_get_user", return_value="root"):
|
||||
info = await async_get_system_info(hass)
|
||||
assert isinstance(info, dict)
|
||||
@ -57,7 +58,7 @@ async def test_get_system_info_supervisor_not_loaded(hass: HomeAssistant) -> Non
|
||||
"homeassistant.helpers.system_info.is_docker_env", return_value=True
|
||||
), patch(
|
||||
"homeassistant.helpers.system_info.is_official_image", return_value=True
|
||||
), patch("homeassistant.components.hassio.get_info", return_value=None), patch.dict(
|
||||
), patch.object(hassio, "get_info", return_value=None), patch.dict(
|
||||
os.environ, {"SUPERVISOR": "127.0.0.1"}
|
||||
):
|
||||
info = await async_get_system_info(hass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user