From 9b89acea97adaa0183f4d22ff52097e21c3f4348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 3 May 2021 14:26:25 +0200 Subject: [PATCH] Handle Timeout exceptions in system_health (#50017) --- homeassistant/components/system_health/__init__.py | 8 +++++--- tests/components/system_health/test_init.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/system_health/__init__.py b/homeassistant/components/system_health/__init__.py index a7a92d3baf7..c8200e0e10a 100644 --- a/homeassistant/components/system_health/__init__.py +++ b/homeassistant/components/system_health/__init__.py @@ -216,6 +216,8 @@ async def async_check_can_reach_url( return "ok" except aiohttp.ClientError: data = {"type": "failed", "error": "unreachable"} - if more_info is not None: - data["more_info"] = more_info - return data + except asyncio.TimeoutError: + data = {"type": "failed", "error": "timeout"} + if more_info is not None: + data["more_info"] = more_info + return data diff --git a/tests/components/system_health/test_init.py b/tests/components/system_health/test_init.py index 212ec544629..672846ff4e2 100644 --- a/tests/components/system_health/test_init.py +++ b/tests/components/system_health/test_init.py @@ -113,6 +113,7 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock): """Test registering via platform.""" aioclient_mock.get("http://example.com/status", text="") aioclient_mock.get("http://example.com/status_fail", exc=ClientError) + aioclient_mock.get("http://example.com/timeout", exc=asyncio.TimeoutError) hass.config.components.add("fake_integration") mock_platform( hass, @@ -130,6 +131,11 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock): "http://example.com/status_fail", more_info="http://more-info-url.com", ), + "server_timeout": system_health.async_check_can_reach_url( + hass, + "http://example.com/timeout", + more_info="http://more-info-url.com", + ), "async_crash": AsyncMock(side_effect=ValueError)(), } ), @@ -150,6 +156,11 @@ async def test_platform_loading(hass, hass_ws_client, aioclient_mock): "error": "unreachable", "more_info": "http://more-info-url.com", }, + "server_timeout": { + "type": "failed", + "error": "timeout", + "more_info": "http://more-info-url.com", + }, "async_crash": { "type": "failed", "error": "unknown",