system_health.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """Provide info to system health."""
  2. from aiogithubapi.common.const import BASE_API_URL
  3. from homeassistant.components import system_health
  4. from homeassistant.core import HomeAssistant, callback
  5. from .base import HacsBase
  6. from .const import DOMAIN
  7. GITHUB_STATUS = "https://www.githubstatus.com/"
  8. @callback
  9. def async_register(hass: HomeAssistant, register: system_health.SystemHealthRegistration) -> None:
  10. """Register system health callbacks."""
  11. register.domain = "Home Assistant Community Store"
  12. register.async_register_info(system_health_info, "/hacs")
  13. async def system_health_info(hass):
  14. """Get info for the info page."""
  15. hacs: HacsBase = hass.data[DOMAIN]
  16. response = await hacs.githubapi.rate_limit()
  17. data = {
  18. "GitHub API": system_health.async_check_can_reach_url(hass, BASE_API_URL, GITHUB_STATUS),
  19. "GitHub Content": system_health.async_check_can_reach_url(
  20. hass, "https://raw.githubusercontent.com/hacs/integration/main/hacs.json"
  21. ),
  22. "GitHub Web": system_health.async_check_can_reach_url(
  23. hass, "https://github.com/", GITHUB_STATUS
  24. ),
  25. "GitHub API Calls Remaining": response.data.resources.core.remaining,
  26. "Installed Version": hacs.version,
  27. "Stage": hacs.stage,
  28. "Available Repositories": len(hacs.repositories.list_all),
  29. "Downloaded Repositories": len(hacs.repositories.list_downloaded),
  30. }
  31. if hacs.system.disabled:
  32. data["Disabled"] = hacs.system.disabled_reason
  33. return data