settings.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. from pydantic import BaseModel, Field
  2. class AppSettings(BaseModel):
  3. """Application settings schema."""
  4. auto_archive: bool = Field(default=True, description="Automatically archive prints when completed")
  5. save_thumbnails: bool = Field(default=True, description="Extract and save preview images from 3MF files")
  6. capture_finish_photo: bool = Field(
  7. default=True, description="Capture photo from printer camera when print completes"
  8. )
  9. default_filament_cost: float = Field(default=25.0, description="Default filament cost per kg")
  10. currency: str = Field(default="USD", description="Currency for cost tracking")
  11. energy_cost_per_kwh: float = Field(default=0.15, description="Electricity cost per kWh for energy tracking")
  12. energy_tracking_mode: str = Field(
  13. default="total",
  14. description="Energy display mode on stats: 'print' shows sum of per-print energy, 'total' shows lifetime plug consumption",
  15. )
  16. # Spoolman integration
  17. spoolman_enabled: bool = Field(default=False, description="Enable Spoolman integration for filament tracking")
  18. spoolman_url: str = Field(default="", description="Spoolman server URL (e.g., http://localhost:7912)")
  19. spoolman_sync_mode: str = Field(
  20. default="auto", description="Sync mode: 'auto' syncs immediately, 'manual' requires button press"
  21. )
  22. # Updates
  23. check_updates: bool = Field(default=True, description="Automatically check for updates on startup")
  24. # Language
  25. notification_language: str = Field(default="en", description="Language for push notifications (en, de)")
  26. # AMS threshold settings for humidity and temperature coloring
  27. ams_humidity_good: int = Field(default=40, description="Humidity threshold for good (green): <= this value")
  28. ams_humidity_fair: int = Field(
  29. default=60, description="Humidity threshold for fair (orange): <= this value, > is red"
  30. )
  31. ams_temp_good: float = Field(default=28.0, description="Temperature threshold for good (blue): <= this value")
  32. ams_temp_fair: float = Field(
  33. default=35.0, description="Temperature threshold for fair (orange): <= this value, > is red"
  34. )
  35. ams_history_retention_days: int = Field(default=30, description="Number of days to keep AMS sensor history data")
  36. # Date/time display format
  37. date_format: str = Field(default="system", description="Date format: system, us, eu, iso")
  38. time_format: str = Field(default="system", description="Time format: system, 12h, 24h")
  39. # Default printer for operations
  40. default_printer_id: int | None = Field(default=None, description="Default printer ID for uploads, reprints, etc.")
  41. # Telemetry
  42. telemetry_enabled: bool = Field(default=True, description="Send anonymous usage data to help improve BamBuddy")
  43. # Virtual Printer
  44. virtual_printer_enabled: bool = Field(default=False, description="Enable virtual printer for slicer uploads")
  45. virtual_printer_access_code: str = Field(default="", description="Access code for virtual printer authentication")
  46. virtual_printer_mode: str = Field(
  47. default="immediate",
  48. description="Mode: 'immediate' (archive now), 'review' (pending review), or 'print_queue' (add to print queue)",
  49. )
  50. # Dark mode theme settings
  51. dark_style: str = Field(default="classic", description="Dark mode style: classic, glow, vibrant")
  52. dark_background: str = Field(
  53. default="neutral", description="Dark mode background: neutral, warm, cool, oled, slate, forest"
  54. )
  55. dark_accent: str = Field(default="green", description="Dark mode accent: green, teal, blue, orange, purple, red")
  56. # Light mode theme settings
  57. light_style: str = Field(default="classic", description="Light mode style: classic, glow, vibrant")
  58. light_background: str = Field(default="neutral", description="Light mode background: neutral, warm, cool")
  59. light_accent: str = Field(default="green", description="Light mode accent: green, teal, blue, orange, purple, red")
  60. # FTP retry settings for unreliable WiFi connections
  61. ftp_retry_enabled: bool = Field(default=True, description="Enable automatic retry for FTP operations")
  62. ftp_retry_count: int = Field(default=3, description="Number of retry attempts for FTP operations (1-10)")
  63. ftp_retry_delay: int = Field(default=2, description="Seconds to wait between FTP retry attempts (1-30)")
  64. # MQTT Relay settings for publishing events to external broker
  65. mqtt_enabled: bool = Field(default=False, description="Enable MQTT event publishing to external broker")
  66. mqtt_broker: str = Field(default="", description="MQTT broker hostname or IP address")
  67. mqtt_port: int = Field(default=1883, description="MQTT broker port (default 1883, TLS typically 8883)")
  68. mqtt_username: str = Field(default="", description="MQTT username for authentication (optional)")
  69. mqtt_password: str = Field(default="", description="MQTT password for authentication (optional)")
  70. mqtt_topic_prefix: str = Field(default="bambuddy", description="Topic prefix for all published messages")
  71. mqtt_use_tls: bool = Field(default=False, description="Use TLS/SSL encryption for MQTT connection")
  72. # Home Assistant integration for smart plug control
  73. ha_enabled: bool = Field(default=False, description="Enable Home Assistant integration for smart plug control")
  74. ha_url: str = Field(default="", description="Home Assistant URL (e.g., http://192.168.1.100:8123)")
  75. ha_token: str = Field(default="", description="Home Assistant Long-Lived Access Token")
  76. class AppSettingsUpdate(BaseModel):
  77. """Schema for updating settings (all fields optional)."""
  78. auto_archive: bool | None = None
  79. save_thumbnails: bool | None = None
  80. capture_finish_photo: bool | None = None
  81. default_filament_cost: float | None = None
  82. currency: str | None = None
  83. energy_cost_per_kwh: float | None = None
  84. energy_tracking_mode: str | None = None
  85. spoolman_enabled: bool | None = None
  86. spoolman_url: str | None = None
  87. spoolman_sync_mode: str | None = None
  88. check_updates: bool | None = None
  89. notification_language: str | None = None
  90. ams_humidity_good: int | None = None
  91. ams_humidity_fair: int | None = None
  92. ams_temp_good: float | None = None
  93. ams_temp_fair: float | None = None
  94. ams_history_retention_days: int | None = None
  95. date_format: str | None = None
  96. time_format: str | None = None
  97. default_printer_id: int | None = None
  98. telemetry_enabled: bool | None = None
  99. virtual_printer_enabled: bool | None = None
  100. virtual_printer_access_code: str | None = None
  101. virtual_printer_mode: str | None = None
  102. dark_style: str | None = None
  103. dark_background: str | None = None
  104. dark_accent: str | None = None
  105. light_style: str | None = None
  106. light_background: str | None = None
  107. light_accent: str | None = None
  108. ftp_retry_enabled: bool | None = None
  109. ftp_retry_count: int | None = None
  110. ftp_retry_delay: int | None = None
  111. mqtt_enabled: bool | None = None
  112. mqtt_broker: str | None = None
  113. mqtt_port: int | None = None
  114. mqtt_username: str | None = None
  115. mqtt_password: str | None = None
  116. mqtt_topic_prefix: str | None = None
  117. mqtt_use_tls: bool | None = None
  118. ha_enabled: bool | None = None
  119. ha_url: str | None = None
  120. ha_token: str | None = None