settings.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. spoolman_disable_weight_sync: bool = Field(
  23. default=False,
  24. description="Disable remaining_weight sync. When enabled, only location is updated for existing spools.",
  25. )
  26. spoolman_report_partial_usage: bool = Field(
  27. default=True,
  28. description="Report Partial Usage for Failed Prints. When a print fails or is cancelled, report the estimated filament used up to that point based on layer progress.",
  29. )
  30. disable_filament_warnings: bool = Field(
  31. default=False,
  32. description="Disable insufficient filament warnings when printing or queueing prints",
  33. )
  34. # Updates
  35. check_updates: bool = Field(default=True, description="Automatically check for updates on startup")
  36. check_printer_firmware: bool = Field(default=True, description="Check for printer firmware updates from Bambu Lab")
  37. include_beta_updates: bool = Field(default=False, description="Include beta/prerelease versions in update checks")
  38. # Language
  39. language: str = Field(default="en", description="UI language (en, de, fr, ja, it, pt-BR)")
  40. notification_language: str = Field(default="en", description="Language for push notifications (en, de)")
  41. # Bed cooled notification threshold
  42. bed_cooled_threshold: float = Field(
  43. default=35.0, description="Bed temperature threshold for cooled notification (°C)"
  44. )
  45. # AMS threshold settings for humidity and temperature coloring
  46. ams_humidity_good: int = Field(default=40, description="Humidity threshold for good (green): <= this value")
  47. ams_humidity_fair: int = Field(
  48. default=60, description="Humidity threshold for fair (orange): <= this value, > is red"
  49. )
  50. ams_temp_good: float = Field(default=28.0, description="Temperature threshold for good (blue): <= this value")
  51. ams_temp_fair: float = Field(
  52. default=35.0, description="Temperature threshold for fair (orange): <= this value, > is red"
  53. )
  54. ams_history_retention_days: int = Field(default=30, description="Number of days to keep AMS sensor history data")
  55. # Queue auto-drying settings
  56. queue_drying_enabled: bool = Field(
  57. default=False, description="Automatically dry AMS filament between queued prints"
  58. )
  59. queue_drying_block: bool = Field(
  60. default=False,
  61. description="Block queue until drying completes (when disabled, prints take priority over drying)",
  62. )
  63. ambient_drying_enabled: bool = Field(
  64. default=False,
  65. description="Automatically dry AMS filament on idle printers when humidity exceeds threshold, regardless of queue",
  66. )
  67. drying_presets: str = Field(
  68. default="",
  69. description="JSON blob of drying presets per filament type (empty = use built-in defaults)",
  70. )
  71. # Print modal settings
  72. per_printer_mapping_expanded: bool = Field(
  73. default=False, description="Expand custom filament mapping by default in print modal"
  74. )
  75. # Date/time display format
  76. date_format: str = Field(default="system", description="Date format: system, us, eu, iso")
  77. time_format: str = Field(default="system", description="Time format: system, 12h, 24h")
  78. # Default printer for operations
  79. default_printer_id: int | None = Field(default=None, description="Default printer ID for uploads, reprints, etc.")
  80. # Virtual Printer
  81. virtual_printer_enabled: bool = Field(default=False, description="Enable virtual printer for slicer uploads")
  82. virtual_printer_access_code: str = Field(default="", description="Access code for virtual printer authentication")
  83. virtual_printer_mode: str = Field(
  84. default="immediate",
  85. description="Mode: 'immediate' (archive now), 'review' (pending review), or 'print_queue' (add to print queue)",
  86. )
  87. # Dark mode theme settings
  88. dark_style: str = Field(default="classic", description="Dark mode style: classic, glow, vibrant")
  89. dark_background: str = Field(
  90. default="neutral", description="Dark mode background: neutral, warm, cool, oled, slate, forest"
  91. )
  92. dark_accent: str = Field(default="green", description="Dark mode accent: green, teal, blue, orange, purple, red")
  93. # Light mode theme settings
  94. light_style: str = Field(default="classic", description="Light mode style: classic, glow, vibrant")
  95. light_background: str = Field(default="neutral", description="Light mode background: neutral, warm, cool")
  96. light_accent: str = Field(default="green", description="Light mode accent: green, teal, blue, orange, purple, red")
  97. # FTP retry settings for unreliable WiFi connections
  98. ftp_retry_enabled: bool = Field(default=True, description="Enable automatic retry for FTP operations")
  99. ftp_retry_count: int = Field(default=3, description="Number of retry attempts for FTP operations (1-10)")
  100. ftp_retry_delay: int = Field(default=2, description="Seconds to wait between FTP retry attempts (1-30)")
  101. ftp_timeout: int = Field(default=30, description="FTP connection timeout in seconds (10-300)")
  102. # MQTT Relay settings for publishing events to external broker
  103. mqtt_enabled: bool = Field(default=False, description="Enable MQTT event publishing to external broker")
  104. mqtt_broker: str = Field(default="", description="MQTT broker hostname or IP address")
  105. mqtt_port: int = Field(default=1883, description="MQTT broker port (default 1883, TLS typically 8883)")
  106. mqtt_username: str = Field(default="", description="MQTT username for authentication (optional)")
  107. mqtt_password: str = Field(default="", description="MQTT password for authentication (optional)")
  108. mqtt_topic_prefix: str = Field(default="bambuddy", description="Topic prefix for all published messages")
  109. mqtt_use_tls: bool = Field(default=False, description="Use TLS/SSL encryption for MQTT connection")
  110. # External URL for notifications
  111. external_url: str = Field(
  112. default="", description="External URL where Bambuddy is accessible (for notification images)"
  113. )
  114. # Home Assistant integration for smart plug control
  115. ha_enabled: bool = Field(default=False, description="Enable Home Assistant integration for smart plug control")
  116. ha_url: str = Field(default="", description="Home Assistant URL (e.g., http://192.168.1.100:8123)")
  117. ha_token: str = Field(default="", description="Home Assistant Long-Lived Access Token")
  118. ha_url_from_env: bool = Field(default=False, description="Whether HA URL is set via HA_URL environment variable")
  119. ha_token_from_env: bool = Field(
  120. default=False, description="Whether HA token is set via HA_TOKEN environment variable"
  121. )
  122. ha_env_managed: bool = Field(
  123. default=False, description="Whether HA integration is fully managed by environment variables"
  124. )
  125. # File Manager / Library settings
  126. library_archive_mode: str = Field(
  127. default="ask",
  128. description="When printing from File Manager, create archive entry: 'always', 'never', or 'ask'",
  129. )
  130. library_disk_warning_gb: float = Field(
  131. default=5.0,
  132. description="Show warning when free disk space falls below this threshold (GB)",
  133. )
  134. # Camera view settings
  135. camera_view_mode: str = Field(
  136. default="window",
  137. description="Camera view mode: 'window' opens in new browser window, 'embedded' shows overlay on main screen",
  138. )
  139. # Preferred slicer application
  140. preferred_slicer: str = Field(
  141. default="bambu_studio",
  142. description="Preferred slicer: 'bambu_studio' or 'orcaslicer'",
  143. )
  144. # Prometheus metrics endpoint
  145. prometheus_enabled: bool = Field(default=False, description="Enable Prometheus metrics endpoint at /metrics")
  146. prometheus_token: str = Field(
  147. default="", description="Bearer token for Prometheus metrics authentication (optional)"
  148. )
  149. # Inventory low stock threshold
  150. low_stock_threshold: float = Field(
  151. default=20.0,
  152. ge=0.1,
  153. le=99.9,
  154. description="Low stock threshold percentage (%) for inventory filtering and display",
  155. )
  156. # User email notifications (requires Advanced Authentication)
  157. user_notifications_enabled: bool = Field(
  158. default=True,
  159. description="Enable user email notifications for print job events (requires Advanced Authentication)",
  160. )
  161. class AppSettingsUpdate(BaseModel):
  162. """Schema for updating settings (all fields optional)."""
  163. auto_archive: bool | None = None
  164. save_thumbnails: bool | None = None
  165. capture_finish_photo: bool | None = None
  166. default_filament_cost: float | None = None
  167. currency: str | None = None
  168. energy_cost_per_kwh: float | None = None
  169. energy_tracking_mode: str | None = None
  170. spoolman_enabled: bool | None = None
  171. spoolman_url: str | None = None
  172. spoolman_sync_mode: str | None = None
  173. spoolman_disable_weight_sync: bool | None = None
  174. spoolman_report_partial_usage: bool | None = None
  175. disable_filament_warnings: bool | None = None
  176. check_updates: bool | None = None
  177. check_printer_firmware: bool | None = None
  178. include_beta_updates: bool | None = None
  179. language: str | None = None
  180. notification_language: str | None = None
  181. bed_cooled_threshold: float | None = None
  182. ams_humidity_good: int | None = None
  183. ams_humidity_fair: int | None = None
  184. ams_temp_good: float | None = None
  185. ams_temp_fair: float | None = None
  186. ams_history_retention_days: int | None = None
  187. queue_drying_enabled: bool | None = None
  188. queue_drying_block: bool | None = None
  189. ambient_drying_enabled: bool | None = None
  190. drying_presets: str | None = None
  191. per_printer_mapping_expanded: bool | None = None
  192. date_format: str | None = None
  193. time_format: str | None = None
  194. default_printer_id: int | None = None
  195. virtual_printer_enabled: bool | None = None
  196. virtual_printer_access_code: str | None = None
  197. virtual_printer_mode: str | None = None
  198. dark_style: str | None = None
  199. dark_background: str | None = None
  200. dark_accent: str | None = None
  201. light_style: str | None = None
  202. light_background: str | None = None
  203. light_accent: str | None = None
  204. ftp_retry_enabled: bool | None = None
  205. ftp_retry_count: int | None = None
  206. ftp_retry_delay: int | None = None
  207. ftp_timeout: int | None = None
  208. mqtt_enabled: bool | None = None
  209. mqtt_broker: str | None = None
  210. mqtt_port: int | None = None
  211. mqtt_username: str | None = None
  212. mqtt_password: str | None = None
  213. mqtt_topic_prefix: str | None = None
  214. mqtt_use_tls: bool | None = None
  215. external_url: str | None = None
  216. ha_enabled: bool | None = None
  217. ha_url: str | None = None
  218. ha_token: str | None = None
  219. library_archive_mode: str | None = None
  220. library_disk_warning_gb: float | None = None
  221. camera_view_mode: str | None = None
  222. preferred_slicer: str | None = None
  223. prometheus_enabled: bool | None = None
  224. prometheus_token: str | None = None
  225. low_stock_threshold: float | None = Field(default=None, ge=0.1, le=99.9)
  226. user_notifications_enabled: bool | None = None