mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Add system health check to IPMA (#43762)
This commit is contained in:
parent
0de9e8e952
commit
3e24868a9e
@ -13,5 +13,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": { "name_exists": "Name already exists" }
|
"error": { "name_exists": "Name already exists" }
|
||||||
|
},
|
||||||
|
"system_health": {
|
||||||
|
"info": {
|
||||||
|
"api_endpoint_reachable": "IPMA API endpoint reachable"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
homeassistant/components/ipma/system_health.py
Normal file
22
homeassistant/components/ipma/system_health.py
Normal 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
|
||||||
|
)
|
||||||
|
}
|
23
tests/components/ipma/test_system_health.py
Normal file
23
tests/components/ipma/test_system_health.py
Normal 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"}
|
Loading…
x
Reference in New Issue
Block a user