System health improvement (#43066)

This commit is contained in:
Paulus Schoutsen 2020-11-10 23:56:50 +01:00 committed by GitHub
parent 55a6d37f2c
commit 7745408440
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 125 additions and 29 deletions

View file

@ -0,0 +1,16 @@
{
"system_health": {
"info": {
"can_reach_cert_server": "Reach Certificate Server",
"can_reach_cloud": "Reach Home Assistant Cloud",
"can_reach_cloud_auth": "Reach Authentication Server",
"relayer_connected": "Relayer Connected",
"remote_connected": "Remote Connected",
"remote_enabled": "Remote Enabled",
"alexa_enabled": "Alexa Enabled",
"google_enabled": "Google Enabled",
"logged_in": "Logged In",
"subscription_expiration": "Subscription Expiration"
}
}
}

View file

@ -0,0 +1,16 @@
{
"system_health": {
"info": {
"alexa_enabled": "Alexa Enabled",
"can_reach_cert_server": "Reach Certificate Server",
"can_reach_cloud": "Reach Home Assistant Cloud",
"can_reach_cloud_auth": "Reach Authentication Server",
"google_enabled": "Google Enabled",
"logged_in": "Logged In",
"relayer_connected": "Relayer Connected",
"remote_connected": "Remote Connected",
"remote_enabled": "Remote Enabled",
"subscription_expiration": "Subscription Expiration"
}
}
}

View file

@ -0,0 +1,20 @@
{
"system_health": {
"info": {
"installation_type": "Installation Type",
"version": "Version",
"dev": "Development",
"virtualenv": "Virtual Environment",
"python_version": "Python Version",
"docker": "Docker",
"arch": "CPU Architecture",
"timezone": "Timezone",
"os_name": "Operating System Name",
"os_version": "Operating System Version",
"supervisor": "Supervisor",
"host_os": "Home Assistant OS",
"chassis": "Chassis",
"docker_version": "Docker"
}
}
}

View file

@ -0,0 +1,19 @@
"""Provide info to system health."""
from homeassistant.components import system_health
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import system_info
@callback
def async_register(
hass: HomeAssistant, register: system_health.SystemHealthRegistration
) -> None:
"""Register system health callbacks."""
register.async_register_info(system_health_info)
async def system_health_info(hass):
"""Get info for the info page."""
info = await system_info.async_get_system_info(hass)
info.pop("hassio")
return info

View file

@ -1,3 +1,20 @@
{
"title": "Home Assistant"
"system_health": {
"info": {
"arch": "CPU Architecture",
"chassis": "Chassis",
"dev": "Development",
"docker": "Docker",
"docker_version": "Docker",
"host_os": "Home Assistant OS",
"installation_type": "Installation Type",
"os_name": "Operating System Name",
"os_version": "Operating System Version",
"python_version": "Python Version",
"supervisor": "Supervisor",
"timezone": "Timezone",
"version": "Version",
"virtualenv": "Virtual Environment"
}
}
}

View file

@ -0,0 +1,9 @@
{
"system_health": {
"info": {
"dashboards": "Dashboards",
"mode": "Mode",
"resources": "Resources"
}
}
}

View file

@ -1,3 +1,9 @@
{
"title": "Lovelace"
"system_health": {
"info": {
"dashboards": "Dashboards",
"mode": "Mode",
"resources": "Resources"
}
}
}

View file

@ -94,10 +94,6 @@ async def handle_info(
"""Handle an info request via a subscription."""
registrations: Dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
data = {}
data["homeassistant"] = {
"info": await hass.helpers.system_info.async_get_system_info()
}
pending_info = {}
for domain, domain_data in zip(

View file

@ -47,8 +47,8 @@ async def async_get_system_info(hass: HomeAssistantType) -> Dict[str, Any]:
info_object["supervisor"] = info.get("supervisor")
info_object["host_os"] = host.get("operating_system")
info_object["chassis"] = host.get("chassis")
info_object["docker_version"] = info.get("docker")
info_object["chassis"] = host.get("chassis")
if info.get("hassos") is not None:
info_object["installation_type"] = "Home Assistant OS"

View file

@ -137,6 +137,9 @@ def gen_strings_schema(config: Config, integration: Integration):
cv.schema_with_slug_keys(str, slug_validator=lowercase_validator),
slug_validator=vol.Any("_", cv.slug),
),
vol.Optional("system_health"): {
vol.Optional("info"): {str: cv.string_with_no_html}
},
}
)

View file

@ -2,23 +2,14 @@
import asyncio
from aiohttp.client_exceptions import ClientError
import pytest
from homeassistant.components import system_health
from homeassistant.setup import async_setup_component
from tests.async_mock import AsyncMock, Mock
from tests.async_mock import AsyncMock, Mock, patch
from tests.common import get_system_health_info, mock_platform
@pytest.fixture
def mock_system_info(hass):
"""Mock system info."""
hass.helpers.system_info.async_get_system_info = AsyncMock(
return_value={"hello": True}
)
async def gather_system_health_info(hass, hass_ws_client):
"""Gather all info."""
client = await hass_ws_client(hass)
@ -53,9 +44,16 @@ async def gather_system_health_info(hass, hass_ws_client):
return data
async def test_info_endpoint_return_info(hass, hass_ws_client, mock_system_info):
async def test_info_endpoint_return_info(hass, hass_ws_client):
"""Test that the info endpoint works."""
assert await async_setup_component(hass, "system_health", {})
assert await async_setup_component(hass, "homeassistant", {})
with patch(
"homeassistant.components.homeassistant.system_health.system_health_info",
return_value={"hello": True},
):
assert await async_setup_component(hass, "system_health", {})
data = await gather_system_health_info(hass, hass_ws_client)
assert len(data) == 1
@ -63,7 +61,7 @@ async def test_info_endpoint_return_info(hass, hass_ws_client, mock_system_info)
assert data == {"info": {"hello": True}}
async def test_info_endpoint_register_callback(hass, hass_ws_client, mock_system_info):
async def test_info_endpoint_register_callback(hass, hass_ws_client):
"""Test that the info endpoint allows registering callbacks."""
async def mock_info(hass):
@ -73,7 +71,7 @@ async def test_info_endpoint_register_callback(hass, hass_ws_client, mock_system
assert await async_setup_component(hass, "system_health", {})
data = await gather_system_health_info(hass, hass_ws_client)
assert len(data) == 2
assert len(data) == 1
data = data["lovelace"]
assert data == {"info": {"storage": "YAML"}}
@ -81,9 +79,7 @@ async def test_info_endpoint_register_callback(hass, hass_ws_client, mock_system
assert await get_system_health_info(hass, "lovelace") == {"storage": "YAML"}
async def test_info_endpoint_register_callback_timeout(
hass, hass_ws_client, mock_system_info
):
async def test_info_endpoint_register_callback_timeout(hass, hass_ws_client):
"""Test that the info endpoint timing out."""
async def mock_info(hass):
@ -93,14 +89,12 @@ async def test_info_endpoint_register_callback_timeout(
assert await async_setup_component(hass, "system_health", {})
data = await gather_system_health_info(hass, hass_ws_client)
assert len(data) == 2
assert len(data) == 1
data = data["lovelace"]
assert data == {"info": {"error": {"type": "failed", "error": "timeout"}}}
async def test_info_endpoint_register_callback_exc(
hass, hass_ws_client, mock_system_info
):
async def test_info_endpoint_register_callback_exc(hass, hass_ws_client):
"""Test that the info endpoint requires auth."""
async def mock_info(hass):
@ -110,7 +104,7 @@ async def test_info_endpoint_register_callback_exc(
assert await async_setup_component(hass, "system_health", {})
data = await gather_system_health_info(hass, hass_ws_client)
assert len(data) == 2
assert len(data) == 1
data = data["lovelace"]
assert data == {"info": {"error": {"type": "failed", "error": "unknown"}}}