1
mirror of https://github.com/home-assistant/core synced 2024-08-31 05:57:13 +02:00

Add system health check to IPMA (#43762)

This commit is contained in:
Diogo Gomes 2020-11-30 15:24:18 +00:00 committed by GitHub
parent 0de9e8e952
commit 3e24868a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View File

@ -13,5 +13,10 @@
}
},
"error": { "name_exists": "Name already exists" }
},
"system_health": {
"info": {
"api_endpoint_reachable": "IPMA API endpoint reachable"
}
}
}

View File

@ -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
)
}

View File

@ -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"}