critical.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """Register info websocket commands."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from homeassistant.components import websocket_api
  5. from homeassistant.core import HomeAssistant
  6. import homeassistant.helpers.config_validation as cv
  7. import voluptuous as vol
  8. from ..utils.store import async_load_from_store, async_save_to_store
  9. @websocket_api.websocket_command(
  10. {
  11. vol.Required("type"): "hacs/critical/list",
  12. }
  13. )
  14. @websocket_api.require_admin
  15. @websocket_api.async_response
  16. async def hacs_critical_list(
  17. hass: HomeAssistant,
  18. connection: websocket_api.ActiveConnection,
  19. msg: dict[str, Any],
  20. ):
  21. """List critical repositories."""
  22. connection.send_message(
  23. websocket_api.result_message(
  24. msg["id"],
  25. (await async_load_from_store(hass, "critical") or []),
  26. )
  27. )
  28. @websocket_api.websocket_command(
  29. {
  30. vol.Required("type"): "hacs/critical/acknowledge",
  31. vol.Optional("repository"): cv.string,
  32. }
  33. )
  34. @websocket_api.require_admin
  35. @websocket_api.async_response
  36. async def hacs_critical_acknowledge(
  37. hass: HomeAssistant,
  38. connection: websocket_api.ActiveConnection,
  39. msg: dict[str, Any],
  40. ):
  41. """Acknowledge critical repository."""
  42. repository = msg["repository"]
  43. critical = await async_load_from_store(hass, "critical")
  44. for repo in critical:
  45. if repository == repo["repository"]:
  46. repo["acknowledged"] = True
  47. await async_save_to_store(hass, "critical", critical)
  48. connection.send_message(websocket_api.result_message(msg["id"], critical))