diff --git a/homeassistant/components/ipma/strings.json b/homeassistant/components/ipma/strings.json index bf0cf7a9ff8..24f142938d0 100644 --- a/homeassistant/components/ipma/strings.json +++ b/homeassistant/components/ipma/strings.json @@ -13,5 +13,10 @@ } }, "error": { "name_exists": "Name already exists" } + }, + "system_health": { + "info": { + "api_endpoint_reachable": "IPMA API endpoint reachable" + } } } diff --git a/homeassistant/components/ipma/system_health.py b/homeassistant/components/ipma/system_health.py new file mode 100644 index 00000000000..cd783490c35 --- /dev/null +++ b/homeassistant/components/ipma/system_health.py @@ -0,0 +1,22 @@ +"""Provide info to system health.""" +from homeassistant.components import system_health +from homeassistant.core import HomeAssistant, callback + +IPMA_API_URL = "http://api.ipma.pt" + + +@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.""" + return { + "api_endpoint_reachable": system_health.async_check_can_reach_url( + hass, IPMA_API_URL + ) + } diff --git a/tests/components/ipma/test_system_health.py b/tests/components/ipma/test_system_health.py new file mode 100644 index 00000000000..301621514f9 --- /dev/null +++ b/tests/components/ipma/test_system_health.py @@ -0,0 +1,23 @@ +"""Test ipma system health.""" +import asyncio + +from homeassistant.components.ipma.system_health import IPMA_API_URL +from homeassistant.setup import async_setup_component + +from tests.common import get_system_health_info + + +async def test_ipma_system_health(hass, aioclient_mock): + """Test ipma system health.""" + aioclient_mock.get(IPMA_API_URL, json={"result": "ok", "data": {}}) + + hass.config.components.add("ipma") + assert await async_setup_component(hass, "system_health", {}) + + info = await get_system_health_info(hass, "ipma") + + for key, val in info.items(): + if asyncio.iscoroutine(val): + info[key] = await val + + assert info == {"api_endpoint_reachable": "ok"}