kprofile.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """Pydantic schemas for K-profile (pressure advance) management."""
  2. from pydantic import BaseModel
  3. from backend.app.schemas.not_null import IgnoresNullForRequiredColumns
  4. class KProfile(BaseModel):
  5. """A pressure advance (K) calibration profile stored on the printer."""
  6. slot_id: int # Storage slot on printer (limited capacity ~20 slots)
  7. extruder_id: int = 0 # 0 or 1 for dual nozzle printers
  8. nozzle_id: str # e.g., "HS00-0.4" (hardened steel 0.4mm)
  9. nozzle_diameter: str # e.g., "0.4"
  10. filament_id: str # Bambu filament identifier
  11. name: str # User-defined name for the profile
  12. k_value: str # Pressure advance coefficient as string, e.g., "0.020000"
  13. n_coef: str = "0.000000" # N coefficient (usually 0)
  14. ams_id: int = 0 # AMS unit ID
  15. tray_id: int = -1 # AMS tray ID (-1 if not linked)
  16. setting_id: str | None = None # Unique setting identifier
  17. class KProfileCreate(BaseModel):
  18. """Schema for creating/updating a K-profile."""
  19. slot_id: int = 0 # Storage slot, 0 for new profiles
  20. extruder_id: int = 0
  21. nozzle_id: str
  22. nozzle_diameter: str
  23. filament_id: str
  24. name: str
  25. k_value: str
  26. n_coef: str = "0.000000"
  27. ams_id: int = 0
  28. tray_id: int = -1
  29. setting_id: str | None = None
  30. class KProfilesResponse(BaseModel):
  31. """Response containing K-profiles from a printer."""
  32. profiles: list[KProfile]
  33. nozzle_diameter: str # Current nozzle filter
  34. class KProfileDelete(BaseModel):
  35. """Schema for deleting a K-profile."""
  36. slot_id: int # cali_idx - calibration index to delete
  37. extruder_id: int = 0
  38. nozzle_id: str # e.g., "HH00-0.4"
  39. nozzle_diameter: str # e.g., "0.4"
  40. filament_id: str # Bambu filament identifier
  41. setting_id: str | None = None # Setting ID (for X1C series)
  42. class KProfileNote(IgnoresNullForRequiredColumns):
  43. """Schema for K-profile notes (stored locally, not on printer)."""
  44. __orm_table__ = "kprofile_notes"
  45. setting_id: str # Unique identifier for the K-profile
  46. note: str # The note content
  47. class KProfileNoteResponse(BaseModel):
  48. """Response containing notes for K-profiles."""
  49. notes: dict[str, str] # mapping of setting_id -> note