Home Assistant Unofficial Reference 2024.12.1
system_health.py
Go to the documentation of this file.
1 """Provide info to system health."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pyisy import ISY
8 
9 from homeassistant.components import system_health
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.const import CONF_HOST
12 from homeassistant.core import HomeAssistant, callback
13 
14 from .const import DOMAIN, ISY_URL_POSTFIX
15 from .models import IsyData
16 
17 
18 @callback
20  hass: HomeAssistant, register: system_health.SystemHealthRegistration
21 ) -> None:
22  """Register system health callbacks."""
23  register.async_register_info(system_health_info)
24 
25 
26 async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
27  """Get info for the info page."""
28 
29  health_info = {}
30  config_entry_id = next(
31  iter(hass.data[DOMAIN])
32  ) # Only first ISY is supported for now
33  isy_data: IsyData = hass.data[DOMAIN][config_entry_id]
34  isy: ISY = isy_data.root
35 
36  entry = hass.config_entries.async_get_entry(config_entry_id)
37  assert isinstance(entry, ConfigEntry)
38  health_info["host_reachable"] = await system_health.async_check_can_reach_url(
39  hass, f"{entry.data[CONF_HOST]}{ISY_URL_POSTFIX}"
40  )
41  health_info["device_connected"] = isy.connected
42  health_info["last_heartbeat"] = isy.websocket.last_heartbeat
43  health_info["websocket_status"] = isy.websocket.status
44 
45  return health_info
dict[str, Any] system_health_info(HomeAssistant hass)
None async_register(HomeAssistant hass, system_health.SystemHealthRegistration register)