From 774540844062861aac3239f253b6f93935e308f8 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 10 Nov 2020 23:56:50 +0100 Subject: [PATCH] System health improvement (#43066) --- homeassistant/components/cloud/strings.json | 16 ++++++++ .../components/cloud/translations/en.json | 16 ++++++++ .../components/homeassistant/strings.json | 20 ++++++++++ .../components/homeassistant/system_health.py | 19 ++++++++++ .../homeassistant/translations/en.json | 19 +++++++++- .../components/lovelace/strings.json | 9 +++++ .../components/lovelace/translations/en.json | 8 +++- .../components/system_health/__init__.py | 4 -- homeassistant/helpers/system_info.py | 2 +- script/hassfest/translations.py | 3 ++ tests/components/system_health/test_init.py | 38 ++++++++----------- 11 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 homeassistant/components/cloud/strings.json create mode 100644 homeassistant/components/cloud/translations/en.json create mode 100644 homeassistant/components/homeassistant/strings.json create mode 100644 homeassistant/components/homeassistant/system_health.py create mode 100644 homeassistant/components/lovelace/strings.json diff --git a/homeassistant/components/cloud/strings.json b/homeassistant/components/cloud/strings.json new file mode 100644 index 00000000000..357575c7bd0 --- /dev/null +++ b/homeassistant/components/cloud/strings.json @@ -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" + } + } +} diff --git a/homeassistant/components/cloud/translations/en.json b/homeassistant/components/cloud/translations/en.json new file mode 100644 index 00000000000..34af1f57cfa --- /dev/null +++ b/homeassistant/components/cloud/translations/en.json @@ -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" + } + } +} \ No newline at end of file diff --git a/homeassistant/components/homeassistant/strings.json b/homeassistant/components/homeassistant/strings.json new file mode 100644 index 00000000000..e349cc1cb83 --- /dev/null +++ b/homeassistant/components/homeassistant/strings.json @@ -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" + } + } +} diff --git a/homeassistant/components/homeassistant/system_health.py b/homeassistant/components/homeassistant/system_health.py new file mode 100644 index 00000000000..af1be3bd0a5 --- /dev/null +++ b/homeassistant/components/homeassistant/system_health.py @@ -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 diff --git a/homeassistant/components/homeassistant/translations/en.json b/homeassistant/components/homeassistant/translations/en.json index 04b5b760f60..9885785fa4d 100644 --- a/homeassistant/components/homeassistant/translations/en.json +++ b/homeassistant/components/homeassistant/translations/en.json @@ -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" + } + } } \ No newline at end of file diff --git a/homeassistant/components/lovelace/strings.json b/homeassistant/components/lovelace/strings.json new file mode 100644 index 00000000000..6d79805105d --- /dev/null +++ b/homeassistant/components/lovelace/strings.json @@ -0,0 +1,9 @@ +{ + "system_health": { + "info": { + "dashboards": "Dashboards", + "mode": "Mode", + "resources": "Resources" + } + } +} diff --git a/homeassistant/components/lovelace/translations/en.json b/homeassistant/components/lovelace/translations/en.json index 2fc0c81a46c..a1acdafac6a 100644 --- a/homeassistant/components/lovelace/translations/en.json +++ b/homeassistant/components/lovelace/translations/en.json @@ -1,3 +1,9 @@ { - "title": "Lovelace" + "system_health": { + "info": { + "dashboards": "Dashboards", + "mode": "Mode", + "resources": "Resources" + } + } } \ No newline at end of file diff --git a/homeassistant/components/system_health/__init__.py b/homeassistant/components/system_health/__init__.py index 97e98d211c0..c53cd9da1a5 100644 --- a/homeassistant/components/system_health/__init__.py +++ b/homeassistant/components/system_health/__init__.py @@ -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( diff --git a/homeassistant/helpers/system_info.py b/homeassistant/helpers/system_info.py index 12fc07dfbd8..9c2c4b181ad 100644 --- a/homeassistant/helpers/system_info.py +++ b/homeassistant/helpers/system_info.py @@ -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" diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 6f94b88816c..17da80c3e8a 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -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} + }, } ) diff --git a/tests/components/system_health/test_init.py b/tests/components/system_health/test_init.py index a3ca4aab449..28f54c81c42 100644 --- a/tests/components/system_health/test_init.py +++ b/tests/components/system_health/test_init.py @@ -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"}}}