printer.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from datetime import datetime
  2. from pydantic import BaseModel, Field
  3. class PrinterBase(BaseModel):
  4. name: str = Field(..., min_length=1, max_length=100)
  5. serial_number: str = Field(..., min_length=1, max_length=50)
  6. ip_address: str = Field(..., pattern=r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
  7. access_code: str = Field(..., min_length=1, max_length=20)
  8. model: str | None = None
  9. location: str | None = None # Group/location name
  10. auto_archive: bool = True
  11. class PrinterCreate(PrinterBase):
  12. pass
  13. class PrinterUpdate(BaseModel):
  14. name: str | None = None
  15. ip_address: str | None = None
  16. access_code: str | None = None
  17. model: str | None = None
  18. location: str | None = None
  19. is_active: bool | None = None
  20. auto_archive: bool | None = None
  21. print_hours_offset: float | None = None
  22. class PrinterResponse(PrinterBase):
  23. id: int
  24. is_active: bool
  25. nozzle_count: int = 1 # 1 or 2, auto-detected from MQTT
  26. print_hours_offset: float = 0.0
  27. created_at: datetime
  28. updated_at: datetime
  29. class Config:
  30. from_attributes = True
  31. class HMSErrorResponse(BaseModel):
  32. code: str
  33. attr: int = 0 # Attribute value for constructing wiki URL
  34. module: int
  35. severity: int # 1=fatal, 2=serious, 3=common, 4=info
  36. class AMSTray(BaseModel):
  37. id: int
  38. tray_color: str | None = None
  39. tray_type: str | None = None
  40. tray_sub_brands: str | None = None # Full name like "PLA Basic", "PETG HF"
  41. tray_id_name: str | None = None # Bambu filament ID like "A00-Y2" (can decode to color)
  42. tray_info_idx: str | None = None # Filament preset ID like "GFA00"
  43. remain: int = 0
  44. k: float | None = None # Pressure advance value (from tray or K-profile lookup)
  45. cali_idx: int | None = None # Calibration index for K-profile lookup
  46. tag_uid: str | None = None # RFID tag UID (any tag)
  47. tray_uuid: str | None = None # Bambu Lab spool UUID (32-char hex)
  48. nozzle_temp_min: int | None = None # Min nozzle temperature
  49. nozzle_temp_max: int | None = None # Max nozzle temperature
  50. class AMSUnit(BaseModel):
  51. id: int
  52. humidity: int | None = None
  53. temp: float | None = None
  54. is_ams_ht: bool = False # True for AMS-HT (single spool), False for regular AMS (4 spools)
  55. tray: list[AMSTray] = []
  56. class NozzleInfoResponse(BaseModel):
  57. nozzle_type: str = "" # "stainless_steel" or "hardened_steel"
  58. nozzle_diameter: str = "" # e.g., "0.4"
  59. class PrintOptionsResponse(BaseModel):
  60. """AI detection and print options from xcam data."""
  61. # Core AI detectors
  62. spaghetti_detector: bool = False
  63. print_halt: bool = False
  64. halt_print_sensitivity: str = "medium" # Spaghetti sensitivity
  65. first_layer_inspector: bool = False
  66. printing_monitor: bool = False
  67. buildplate_marker_detector: bool = False
  68. allow_skip_parts: bool = False
  69. # Additional AI detectors (decoded from cfg bitmask)
  70. nozzle_clumping_detector: bool = True
  71. nozzle_clumping_sensitivity: str = "medium"
  72. pileup_detector: bool = True
  73. pileup_sensitivity: str = "medium"
  74. airprint_detector: bool = True
  75. airprint_sensitivity: str = "medium"
  76. auto_recovery_step_loss: bool = True
  77. filament_tangle_detect: bool = False
  78. class PrinterStatus(BaseModel):
  79. id: int
  80. name: str
  81. connected: bool
  82. state: str | None = None
  83. current_print: str | None = None
  84. subtask_name: str | None = None
  85. gcode_file: str | None = None
  86. progress: float | None = None
  87. remaining_time: int | None = None
  88. layer_num: int | None = None
  89. total_layers: int | None = None
  90. temperatures: dict | None = None
  91. cover_url: str | None = None
  92. hms_errors: list[HMSErrorResponse] = []
  93. ams: list[AMSUnit] = []
  94. ams_exists: bool = False
  95. vt_tray: AMSTray | None = None # Virtual tray / external spool
  96. sdcard: bool = False # SD card inserted
  97. store_to_sdcard: bool = False # Store sent files on SD card
  98. timelapse: bool = False # Timelapse recording active
  99. ipcam: bool = False # Live view enabled
  100. wifi_signal: int | None = None # WiFi signal strength in dBm
  101. nozzles: list[NozzleInfoResponse] = [] # Nozzle hardware info (index 0=left/primary, 1=right)
  102. print_options: PrintOptionsResponse | None = None # AI detection and print options
  103. # Calibration stage tracking
  104. stg_cur: int = -1 # Current stage number (-1 = not calibrating)
  105. stg_cur_name: str | None = None # Human-readable current stage name
  106. stg: list[int] = [] # List of stage numbers in calibration sequence
  107. # Air conditioning mode (0=cooling, 1=heating)
  108. airduct_mode: int = 0
  109. # Print speed level (1=silent, 2=standard, 3=sport, 4=ludicrous)
  110. speed_level: int = 2
  111. # Chamber light on/off
  112. chamber_light: bool = False
  113. # Active extruder for dual nozzle (0=right, 1=left)
  114. active_extruder: int = 0
  115. # AMS mapping for dual nozzle: which AMS is connected to which nozzle
  116. ams_mapping: list[int] = []
  117. # Per-AMS extruder map: {ams_id: extruder_id} where 0=right, 1=left
  118. ams_extruder_map: dict[str, int] = {}
  119. # Currently loaded tray (global ID): 254 = external spool, 255 = no filament
  120. tray_now: int = 255
  121. # AMS status for filament change tracking
  122. # Main status: 0=idle, 1=filament_change, 2=rfid_identifying, 3=assist, 4=calibration
  123. ams_status_main: int = 0
  124. # Sub status: specific step within filament change (when main=1)
  125. # Known values: 4=retraction, 6=load verification, 7=purge
  126. ams_status_sub: int = 0
  127. # mc_print_sub_stage - filament change step indicator used by OrcaSlicer/BambuStudio
  128. mc_print_sub_stage: int = 0
  129. # Timestamp of last AMS data update (for RFID refresh detection)
  130. last_ams_update: float = 0.0