1 """Helper to gather system info."""
3 from __future__
import annotations
5 from functools
import cache
6 from getpass
import getuser
10 from typing
import TYPE_CHECKING, Any
17 from .hassio
import is_hassio
18 from .importlib
import async_import_module
19 from .singleton
import singleton
21 _LOGGER = logging.getLogger(__name__)
23 _DATA_MAC_VER =
"system_info_mac_ver"
28 """Return True if Home Assistant is running in an official container."""
29 return os.path.isfile(
"/OFFICIAL_IMAGE")
32 @singleton(_DATA_MAC_VER)
34 """Return the macOS version."""
35 return (await hass.async_add_executor_job(platform.mac_ver))[0]
40 cached_get_user = cache(getuser)
45 """Return info about the system."""
59 "installation_type":
"Unknown",
60 "version": current_version,
61 "dev":
"dev" in current_version,
64 "python_version": platform.python_version(),
66 "arch": platform.machine(),
67 "timezone":
str(hass.config.time_zone),
68 "os_name": platform.system(),
69 "os_version": platform.release(),
74 except (KeyError, OSError):
78 info_object[
"user"] =
None
80 if platform.system() ==
"Darwin":
82 elif platform.system() ==
"Linux":
86 if info_object[
"docker"]:
88 info_object[
"installation_type"] =
"Home Assistant Container"
90 info_object[
"installation_type"] =
"Unsupported Third Party Container"
93 info_object[
"installation_type"] =
"Home Assistant Core"
97 if not (info := hassio.get_info(hass)):
98 _LOGGER.warning(
"No Home Assistant Supervisor info available")
101 host = hassio.get_host_info(hass)
or {}
102 info_object[
"supervisor"] = info.get(
"supervisor")
103 info_object[
"host_os"] = host.get(
"operating_system")
104 info_object[
"docker_version"] = info.get(
"docker")
105 info_object[
"chassis"] = host.get(
"chassis")
107 if info.get(
"hassos")
is not None:
108 info_object[
"installation_type"] =
"Home Assistant OS"
110 info_object[
"installation_type"] =
"Home Assistant Supervised"
bool is_hassio(HomeAssistant hass)
ModuleType async_import_module(HomeAssistant hass, str name)
str async_get_mac_ver(HomeAssistant hass)
dict[str, Any] async_get_system_info(HomeAssistant hass)