printer.py 5.2 KB

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