configuration_schema.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. """HACS Configuration Schemas."""
  2. # pylint: disable=dangerous-default-value
  3. import voluptuous as vol
  4. from ..const import LOCALE
  5. # Configuration:
  6. TOKEN = "token"
  7. SIDEPANEL_TITLE = "sidepanel_title"
  8. SIDEPANEL_ICON = "sidepanel_icon"
  9. FRONTEND_REPO = "frontend_repo"
  10. FRONTEND_REPO_URL = "frontend_repo_url"
  11. APPDAEMON = "appdaemon"
  12. NETDAEMON = "netdaemon"
  13. # Options:
  14. COUNTRY = "country"
  15. DEBUG = "debug"
  16. RELEASE_LIMIT = "release_limit"
  17. EXPERIMENTAL = "experimental"
  18. # Config group
  19. PATH_OR_URL = "frontend_repo_path_or_url"
  20. def hacs_base_config_schema(config: dict = {}) -> dict:
  21. """Return a shcema configuration dict for HACS."""
  22. if not config:
  23. config = {
  24. TOKEN: "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
  25. }
  26. return {
  27. vol.Required(TOKEN, default=config.get(TOKEN)): str,
  28. }
  29. def hacs_config_option_schema(options: dict = {}) -> dict:
  30. """Return a shcema for HACS configuration options."""
  31. if not options:
  32. options = {
  33. APPDAEMON: False,
  34. COUNTRY: "ALL",
  35. DEBUG: False,
  36. EXPERIMENTAL: False,
  37. NETDAEMON: False,
  38. RELEASE_LIMIT: 5,
  39. SIDEPANEL_ICON: "hacs:hacs",
  40. SIDEPANEL_TITLE: "HACS",
  41. FRONTEND_REPO: "",
  42. FRONTEND_REPO_URL: "",
  43. }
  44. return {
  45. vol.Optional(SIDEPANEL_TITLE, default=options.get(SIDEPANEL_TITLE)): str,
  46. vol.Optional(SIDEPANEL_ICON, default=options.get(SIDEPANEL_ICON)): str,
  47. vol.Optional(RELEASE_LIMIT, default=options.get(RELEASE_LIMIT)): int,
  48. vol.Optional(COUNTRY, default=options.get(COUNTRY)): vol.In(LOCALE),
  49. vol.Optional(APPDAEMON, default=options.get(APPDAEMON)): bool,
  50. vol.Optional(NETDAEMON, default=options.get(NETDAEMON)): bool,
  51. vol.Optional(DEBUG, default=options.get(DEBUG)): bool,
  52. vol.Optional(EXPERIMENTAL, default=options.get(EXPERIMENTAL)): bool,
  53. vol.Exclusive(FRONTEND_REPO, PATH_OR_URL): str,
  54. vol.Exclusive(FRONTEND_REPO_URL, PATH_OR_URL): str,
  55. }
  56. def hacs_config_combined() -> dict:
  57. """Combine the configuration options."""
  58. base = hacs_base_config_schema()
  59. options = hacs_config_option_schema()
  60. for option in options:
  61. base[option] = options[option]
  62. return base