Add support for system health to GIOS integration (#43280)
* Add system health support * Fix docstrings * Change url to check
This commit is contained in:
parent
25e717c8d2
commit
19389b16e2
3 changed files with 64 additions and 0 deletions
|
@ -18,5 +18,10 @@
|
|||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_location%]"
|
||||
}
|
||||
},
|
||||
"system_health": {
|
||||
"info": {
|
||||
"can_reach_server": "Reach GIO\u015a server"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
homeassistant/components/gios/system_health.py
Normal file
20
homeassistant/components/gios/system_health.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
"""Provide info to system health."""
|
||||
from homeassistant.components import system_health
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
|
||||
API_ENDPOINT = "http://api.gios.gov.pl/"
|
||||
|
||||
|
||||
@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 {
|
||||
"can_reach_server": system_health.async_check_can_reach_url(hass, API_ENDPOINT)
|
||||
}
|
39
tests/components/gios/test_system_health.py
Normal file
39
tests/components/gios/test_system_health.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""Test GIOS system health."""
|
||||
import asyncio
|
||||
|
||||
from aiohttp import ClientError
|
||||
|
||||
from homeassistant.components.gios.const import DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import get_system_health_info
|
||||
|
||||
|
||||
async def test_gios_system_health(hass, aioclient_mock):
|
||||
"""Test GIOS system health."""
|
||||
aioclient_mock.get("http://api.gios.gov.pl/", text="")
|
||||
hass.config.components.add(DOMAIN)
|
||||
assert await async_setup_component(hass, "system_health", {})
|
||||
|
||||
info = await get_system_health_info(hass, DOMAIN)
|
||||
|
||||
for key, val in info.items():
|
||||
if asyncio.iscoroutine(val):
|
||||
info[key] = await val
|
||||
|
||||
assert info == {"can_reach_server": "ok"}
|
||||
|
||||
|
||||
async def test_gios_system_health_fail(hass, aioclient_mock):
|
||||
"""Test GIOS system health."""
|
||||
aioclient_mock.get("http://api.gios.gov.pl/", exc=ClientError)
|
||||
hass.config.components.add(DOMAIN)
|
||||
assert await async_setup_component(hass, "system_health", {})
|
||||
|
||||
info = await get_system_health_info(hass, DOMAIN)
|
||||
|
||||
for key, val in info.items():
|
||||
if asyncio.iscoroutine(val):
|
||||
info[key] = await val
|
||||
|
||||
assert info == {"can_reach_server": {"type": "failed", "error": "unreachable"}}
|
Loading…
Add table
Reference in a new issue