2019-01-30 18:57:53 +00:00
|
|
|
"""Helper to gather system info."""
|
2021-03-17 17:34:19 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-08-03 09:58:27 +00:00
|
|
|
from getpass import getuser
|
2019-01-30 18:57:53 +00:00
|
|
|
import os
|
|
|
|
import platform
|
2021-03-17 17:34:19 +00:00
|
|
|
from typing import Any
|
2019-01-30 18:57:53 +00:00
|
|
|
|
|
|
|
from homeassistant.const import __version__ as current_version
|
2021-03-27 11:55:24 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2019-01-30 18:57:53 +00:00
|
|
|
from homeassistant.loader import bind_hass
|
|
|
|
from homeassistant.util.package import is_virtual_env
|
2019-12-09 15:42:10 +00:00
|
|
|
|
2019-01-30 18:57:53 +00:00
|
|
|
|
|
|
|
@bind_hass
|
2021-03-27 11:55:24 +00:00
|
|
|
async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
2019-01-30 18:57:53 +00:00
|
|
|
"""Return info about the system."""
|
|
|
|
info_object = {
|
2020-05-12 22:27:34 +00:00
|
|
|
"installation_type": "Unknown",
|
2019-07-31 19:25:30 +00:00
|
|
|
"version": current_version,
|
|
|
|
"dev": "dev" in current_version,
|
|
|
|
"hassio": hass.components.hassio.is_hassio(),
|
|
|
|
"virtualenv": is_virtual_env(),
|
|
|
|
"python_version": platform.python_version(),
|
|
|
|
"docker": False,
|
|
|
|
"arch": platform.machine(),
|
|
|
|
"timezone": str(hass.config.time_zone),
|
|
|
|
"os_name": platform.system(),
|
2020-02-27 21:59:30 +00:00
|
|
|
"os_version": platform.release(),
|
2019-01-30 18:57:53 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 09:53:19 +00:00
|
|
|
try:
|
|
|
|
info_object["user"] = getuser()
|
|
|
|
except KeyError:
|
|
|
|
info_object["user"] = None
|
|
|
|
|
2022-01-13 19:41:11 +00:00
|
|
|
if platform.system() == "Darwin":
|
2019-07-31 19:25:30 +00:00
|
|
|
info_object["os_version"] = platform.mac_ver()[0]
|
|
|
|
elif platform.system() == "Linux":
|
|
|
|
info_object["docker"] = os.path.isfile("/.dockerenv")
|
2019-01-30 18:57:53 +00:00
|
|
|
|
2020-05-12 22:27:34 +00:00
|
|
|
# Determine installation type on current data
|
|
|
|
if info_object["docker"]:
|
2022-02-04 17:57:14 +00:00
|
|
|
if info_object["user"] == "root" and os.path.isfile("/OFFICIAL_IMAGE"):
|
2021-08-03 09:58:27 +00:00
|
|
|
info_object["installation_type"] = "Home Assistant Container"
|
2022-02-04 17:57:14 +00:00
|
|
|
else:
|
|
|
|
info_object["installation_type"] = "Unsupported Third Party Container"
|
|
|
|
|
2020-05-12 22:27:34 +00:00
|
|
|
elif is_virtual_env():
|
2020-06-02 08:50:34 +00:00
|
|
|
info_object["installation_type"] = "Home Assistant Core"
|
2020-05-12 22:27:34 +00:00
|
|
|
|
|
|
|
# Enrich with Supervisor information
|
|
|
|
if hass.components.hassio.is_hassio():
|
|
|
|
info = hass.components.hassio.get_info()
|
|
|
|
host = hass.components.hassio.get_host_info()
|
|
|
|
|
|
|
|
info_object["supervisor"] = info.get("supervisor")
|
|
|
|
info_object["host_os"] = host.get("operating_system")
|
2020-06-02 08:50:34 +00:00
|
|
|
info_object["docker_version"] = info.get("docker")
|
2020-11-10 22:56:50 +00:00
|
|
|
info_object["chassis"] = host.get("chassis")
|
2020-05-12 22:27:34 +00:00
|
|
|
|
|
|
|
if info.get("hassos") is not None:
|
2020-06-22 12:46:31 +00:00
|
|
|
info_object["installation_type"] = "Home Assistant OS"
|
2020-05-12 22:27:34 +00:00
|
|
|
else:
|
|
|
|
info_object["installation_type"] = "Home Assistant Supervised"
|
|
|
|
|
2019-01-30 18:57:53 +00:00
|
|
|
return info_object
|