Add user to homeassistant system health (#53902)

This commit is contained in:
Joakim Sørensen 2021-08-03 11:58:27 +02:00 committed by GitHub
parent 27848720a4
commit 3f2e18fe17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

View File

@ -4,6 +4,7 @@
"arch": "CPU Architecture",
"dev": "Development",
"docker": "Docker",
"user": "User",
"hassio": "Supervisor",
"installation_type": "Installation Type",
"os_name": "Operating System Family",
@ -14,4 +15,4 @@
"virtualenv": "Virtual Environment"
}
}
}
}

View File

@ -22,6 +22,7 @@ async def system_health_info(hass):
"dev": info.get("dev"),
"hassio": info.get("hassio"),
"docker": info.get("docker"),
"user": info.get("user"),
"virtualenv": info.get("virtualenv"),
"python_version": info.get("python_version"),
"os_name": info.get("os_name"),

View File

@ -1,6 +1,7 @@
"""Helper to gather system info."""
from __future__ import annotations
from getpass import getuser
import os
import platform
from typing import Any
@ -22,6 +23,7 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
"virtualenv": is_virtual_env(),
"python_version": platform.python_version(),
"docker": False,
"user": getuser(),
"arch": platform.machine(),
"timezone": str(hass.config.time_zone),
"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
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():
info_object["installation_type"] = "Home Assistant Core"

View File

@ -1,5 +1,6 @@
"""Tests for the system info helper."""
import json
from unittest.mock import patch
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()
assert isinstance(info, dict)
assert info["version"] == current_version
assert info["user"] 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"