mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
System health improvement (#43066)
This commit is contained in:
parent
55a6d37f2c
commit
7745408440
16
homeassistant/components/cloud/strings.json
Normal file
16
homeassistant/components/cloud/strings.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
homeassistant/components/cloud/translations/en.json
Normal file
16
homeassistant/components/cloud/translations/en.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
homeassistant/components/homeassistant/strings.json
Normal file
20
homeassistant/components/homeassistant/strings.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
homeassistant/components/homeassistant/system_health.py
Normal file
19
homeassistant/components/homeassistant/system_health.py
Normal 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
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
9
homeassistant/components/lovelace/strings.json
Normal file
9
homeassistant/components/lovelace/strings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"system_health": {
|
||||||
|
"info": {
|
||||||
|
"dashboards": "Dashboards",
|
||||||
|
"mode": "Mode",
|
||||||
|
"resources": "Resources"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,9 @@
|
|||||||
{
|
{
|
||||||
"title": "Lovelace"
|
"system_health": {
|
||||||
|
"info": {
|
||||||
|
"dashboards": "Dashboards",
|
||||||
|
"mode": "Mode",
|
||||||
|
"resources": "Resources"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -94,10 +94,6 @@ async def handle_info(
|
|||||||
"""Handle an info request via a subscription."""
|
"""Handle an info request via a subscription."""
|
||||||
registrations: Dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
|
registrations: Dict[str, SystemHealthRegistration] = hass.data[DOMAIN]
|
||||||
data = {}
|
data = {}
|
||||||
data["homeassistant"] = {
|
|
||||||
"info": await hass.helpers.system_info.async_get_system_info()
|
|
||||||
}
|
|
||||||
|
|
||||||
pending_info = {}
|
pending_info = {}
|
||||||
|
|
||||||
for domain, domain_data in zip(
|
for domain, domain_data in zip(
|
||||||
|
@ -47,8 +47,8 @@ async def async_get_system_info(hass: HomeAssistantType) -> Dict[str, Any]:
|
|||||||
|
|
||||||
info_object["supervisor"] = info.get("supervisor")
|
info_object["supervisor"] = info.get("supervisor")
|
||||||
info_object["host_os"] = host.get("operating_system")
|
info_object["host_os"] = host.get("operating_system")
|
||||||
info_object["chassis"] = host.get("chassis")
|
|
||||||
info_object["docker_version"] = info.get("docker")
|
info_object["docker_version"] = info.get("docker")
|
||||||
|
info_object["chassis"] = host.get("chassis")
|
||||||
|
|
||||||
if info.get("hassos") is not None:
|
if info.get("hassos") is not None:
|
||||||
info_object["installation_type"] = "Home Assistant OS"
|
info_object["installation_type"] = "Home Assistant OS"
|
||||||
|
@ -137,6 +137,9 @@ def gen_strings_schema(config: Config, integration: Integration):
|
|||||||
cv.schema_with_slug_keys(str, slug_validator=lowercase_validator),
|
cv.schema_with_slug_keys(str, slug_validator=lowercase_validator),
|
||||||
slug_validator=vol.Any("_", cv.slug),
|
slug_validator=vol.Any("_", cv.slug),
|
||||||
),
|
),
|
||||||
|
vol.Optional("system_health"): {
|
||||||
|
vol.Optional("info"): {str: cv.string_with_no_html}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,23 +2,14 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientError
|
from aiohttp.client_exceptions import ClientError
|
||||||
import pytest
|
|
||||||
|
|
||||||
from homeassistant.components import system_health
|
from homeassistant.components import system_health
|
||||||
from homeassistant.setup import async_setup_component
|
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
|
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):
|
async def gather_system_health_info(hass, hass_ws_client):
|
||||||
"""Gather all info."""
|
"""Gather all info."""
|
||||||
client = await hass_ws_client(hass)
|
client = await hass_ws_client(hass)
|
||||||
@ -53,9 +44,16 @@ async def gather_system_health_info(hass, hass_ws_client):
|
|||||||
return data
|
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."""
|
"""Test that the info endpoint works."""
|
||||||
|
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", {})
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
|
|
||||||
data = await gather_system_health_info(hass, hass_ws_client)
|
data = await gather_system_health_info(hass, hass_ws_client)
|
||||||
|
|
||||||
assert len(data) == 1
|
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}}
|
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."""
|
"""Test that the info endpoint allows registering callbacks."""
|
||||||
|
|
||||||
async def mock_info(hass):
|
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", {})
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
data = await gather_system_health_info(hass, hass_ws_client)
|
data = await gather_system_health_info(hass, hass_ws_client)
|
||||||
|
|
||||||
assert len(data) == 2
|
assert len(data) == 1
|
||||||
data = data["lovelace"]
|
data = data["lovelace"]
|
||||||
assert data == {"info": {"storage": "YAML"}}
|
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"}
|
assert await get_system_health_info(hass, "lovelace") == {"storage": "YAML"}
|
||||||
|
|
||||||
|
|
||||||
async def test_info_endpoint_register_callback_timeout(
|
async def test_info_endpoint_register_callback_timeout(hass, hass_ws_client):
|
||||||
hass, hass_ws_client, mock_system_info
|
|
||||||
):
|
|
||||||
"""Test that the info endpoint timing out."""
|
"""Test that the info endpoint timing out."""
|
||||||
|
|
||||||
async def mock_info(hass):
|
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", {})
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
data = await gather_system_health_info(hass, hass_ws_client)
|
data = await gather_system_health_info(hass, hass_ws_client)
|
||||||
|
|
||||||
assert len(data) == 2
|
assert len(data) == 1
|
||||||
data = data["lovelace"]
|
data = data["lovelace"]
|
||||||
assert data == {"info": {"error": {"type": "failed", "error": "timeout"}}}
|
assert data == {"info": {"error": {"type": "failed", "error": "timeout"}}}
|
||||||
|
|
||||||
|
|
||||||
async def test_info_endpoint_register_callback_exc(
|
async def test_info_endpoint_register_callback_exc(hass, hass_ws_client):
|
||||||
hass, hass_ws_client, mock_system_info
|
|
||||||
):
|
|
||||||
"""Test that the info endpoint requires auth."""
|
"""Test that the info endpoint requires auth."""
|
||||||
|
|
||||||
async def mock_info(hass):
|
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", {})
|
assert await async_setup_component(hass, "system_health", {})
|
||||||
data = await gather_system_health_info(hass, hass_ws_client)
|
data = await gather_system_health_info(hass, hass_ws_client)
|
||||||
|
|
||||||
assert len(data) == 2
|
assert len(data) == 1
|
||||||
data = data["lovelace"]
|
data = data["lovelace"]
|
||||||
assert data == {"info": {"error": {"type": "failed", "error": "unknown"}}}
|
assert data == {"info": {"error": {"type": "failed", "error": "unknown"}}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user