mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Add user to homeassistant system health (#53902)
This commit is contained in:
parent
27848720a4
commit
3f2e18fe17
@ -4,6 +4,7 @@
|
|||||||
"arch": "CPU Architecture",
|
"arch": "CPU Architecture",
|
||||||
"dev": "Development",
|
"dev": "Development",
|
||||||
"docker": "Docker",
|
"docker": "Docker",
|
||||||
|
"user": "User",
|
||||||
"hassio": "Supervisor",
|
"hassio": "Supervisor",
|
||||||
"installation_type": "Installation Type",
|
"installation_type": "Installation Type",
|
||||||
"os_name": "Operating System Family",
|
"os_name": "Operating System Family",
|
||||||
@ -14,4 +15,4 @@
|
|||||||
"virtualenv": "Virtual Environment"
|
"virtualenv": "Virtual Environment"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,6 +22,7 @@ async def system_health_info(hass):
|
|||||||
"dev": info.get("dev"),
|
"dev": info.get("dev"),
|
||||||
"hassio": info.get("hassio"),
|
"hassio": info.get("hassio"),
|
||||||
"docker": info.get("docker"),
|
"docker": info.get("docker"),
|
||||||
|
"user": info.get("user"),
|
||||||
"virtualenv": info.get("virtualenv"),
|
"virtualenv": info.get("virtualenv"),
|
||||||
"python_version": info.get("python_version"),
|
"python_version": info.get("python_version"),
|
||||||
"os_name": info.get("os_name"),
|
"os_name": info.get("os_name"),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Helper to gather system info."""
|
"""Helper to gather system info."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from getpass import getuser
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -22,6 +23,7 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
|||||||
"virtualenv": is_virtual_env(),
|
"virtualenv": is_virtual_env(),
|
||||||
"python_version": platform.python_version(),
|
"python_version": platform.python_version(),
|
||||||
"docker": False,
|
"docker": False,
|
||||||
|
"user": getuser(),
|
||||||
"arch": platform.machine(),
|
"arch": platform.machine(),
|
||||||
"timezone": str(hass.config.time_zone),
|
"timezone": str(hass.config.time_zone),
|
||||||
"os_name": platform.system(),
|
"os_name": platform.system(),
|
||||||
@ -37,7 +39,8 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
|||||||
|
|
||||||
# Determine installation type on current data
|
# Determine installation type on current data
|
||||||
if info_object["docker"]:
|
if info_object["docker"]:
|
||||||
info_object["installation_type"] = "Home Assistant Container"
|
if info_object["user"] == "root":
|
||||||
|
info_object["installation_type"] = "Home Assistant Container"
|
||||||
elif is_virtual_env():
|
elif is_virtual_env():
|
||||||
info_object["installation_type"] = "Home Assistant Core"
|
info_object["installation_type"] = "Home Assistant Core"
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Tests for the system info helper."""
|
"""Tests for the system info helper."""
|
||||||
import json
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.const import __version__ as current_version
|
from homeassistant.const import __version__ as current_version
|
||||||
|
|
||||||
@ -9,4 +10,20 @@ async def test_get_system_info(hass):
|
|||||||
info = await hass.helpers.system_info.async_get_system_info()
|
info = await hass.helpers.system_info.async_get_system_info()
|
||||||
assert isinstance(info, dict)
|
assert isinstance(info, dict)
|
||||||
assert info["version"] == current_version
|
assert info["version"] == current_version
|
||||||
|
assert info["user"] is not None
|
||||||
assert json.dumps(info) is not None
|
assert json.dumps(info) is not None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_container_installationtype(hass):
|
||||||
|
"""Test container installation type."""
|
||||||
|
with patch("platform.system", return_value="Linux"), patch(
|
||||||
|
"os.path.isfile", return_value=True
|
||||||
|
):
|
||||||
|
info = await hass.helpers.system_info.async_get_system_info()
|
||||||
|
assert info["installation_type"] == "Home Assistant Container"
|
||||||
|
|
||||||
|
with patch("platform.system", return_value="Linux"), patch(
|
||||||
|
"os.path.isfile", return_value=True
|
||||||
|
), patch("homeassistant.helpers.system_info.getuser", return_value="user"):
|
||||||
|
info = await hass.helpers.system_info.async_get_system_info()
|
||||||
|
assert info["installation_type"] == "Unknown"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user