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 typing import Any
4 
5 from homeassistant.components import system_health
6 from homeassistant.core import HomeAssistant, callback
7 
8 from .const import DATA_CLOUD
9 
10 
11 @callback
13  hass: HomeAssistant, register: system_health.SystemHealthRegistration
14 ) -> None:
15  """Register system health callbacks."""
16  register.async_register_info(system_health_info, "/config/cloud")
17 
18 
19 async def system_health_info(hass: HomeAssistant) -> dict[str, Any]:
20  """Get info for the info page."""
21  cloud = hass.data[DATA_CLOUD]
22  client = cloud.client
23 
24  data: dict[str, Any] = {
25  "logged_in": cloud.is_logged_in,
26  }
27 
28  if cloud.is_logged_in:
29  data["subscription_expiration"] = cloud.expiration_date
30  data["relayer_connected"] = cloud.is_connected
31  data["relayer_region"] = client.relayer_region
32  data["remote_enabled"] = client.prefs.remote_enabled
33  data["remote_connected"] = cloud.remote.is_connected
34  data["alexa_enabled"] = client.prefs.alexa_enabled
35  data["google_enabled"] = client.prefs.google_enabled
36  data["cloud_ice_servers_enabled"] = client.prefs.cloud_ice_servers_enabled
37  data["remote_server"] = cloud.remote.snitun_server
38  data["certificate_status"] = cloud.remote.certificate_status
39  data["instance_id"] = client.prefs.instance_id
40 
41  data["can_reach_cert_server"] = system_health.async_check_can_reach_url(
42  hass, f"https://{cloud.acme_server}/directory"
43  )
44  data["can_reach_cloud_auth"] = system_health.async_check_can_reach_url(
45  hass,
46  f"https://cognito-idp.{cloud.region}.amazonaws.com/{cloud.user_pool_id}/.well-known/jwks.json",
47  )
48  data["can_reach_cloud"] = system_health.async_check_can_reach_url(
49  hass, f"https://{cloud.relayer_server}/status"
50  )
51 
52  return data
dict[str, Any] system_health_info(HomeAssistant hass)
None async_register(HomeAssistant hass, system_health.SystemHealthRegistration register)