print_queue.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from datetime import datetime
  2. from typing import Annotated, Literal
  3. from pydantic import BaseModel, PlainSerializer
  4. # Custom serializer to ensure UTC datetimes have Z suffix
  5. def serialize_utc_datetime(dt: datetime | None) -> str | None:
  6. if dt is None:
  7. return None
  8. # Add Z suffix to indicate UTC
  9. return dt.isoformat() + "Z"
  10. UTCDatetime = Annotated[datetime | None, PlainSerializer(serialize_utc_datetime)]
  11. class PrintQueueItemCreate(BaseModel):
  12. printer_id: int | None = None # None = unassigned, user assigns later
  13. archive_id: int
  14. scheduled_time: datetime | None = None # None = ASAP (next when idle)
  15. require_previous_success: bool = False
  16. auto_off_after: bool = False # Power off printer after print completes
  17. manual_start: bool = False # Requires manual trigger to start (staged)
  18. # AMS mapping: list of global tray IDs for each filament slot
  19. # Format: [5, -1, 2, -1] where position = slot_id-1, value = global tray ID (-1 = unused)
  20. ams_mapping: list[int] | None = None
  21. # Plate ID for multi-plate 3MF files (1-indexed, None = auto-detect/plate 1)
  22. plate_id: int | None = None
  23. # Print options
  24. bed_levelling: bool = True
  25. flow_cali: bool = False
  26. vibration_cali: bool = True
  27. layer_inspect: bool = False
  28. timelapse: bool = False
  29. use_ams: bool = True
  30. class PrintQueueItemUpdate(BaseModel):
  31. printer_id: int | None = None
  32. position: int | None = None
  33. scheduled_time: datetime | None = None
  34. require_previous_success: bool | None = None
  35. auto_off_after: bool | None = None
  36. manual_start: bool | None = None
  37. ams_mapping: list[int] | None = None
  38. plate_id: int | None = None
  39. # Print options
  40. bed_levelling: bool | None = None
  41. flow_cali: bool | None = None
  42. vibration_cali: bool | None = None
  43. layer_inspect: bool | None = None
  44. timelapse: bool | None = None
  45. use_ams: bool | None = None
  46. class PrintQueueItemResponse(BaseModel):
  47. id: int
  48. printer_id: int | None # None = unassigned
  49. archive_id: int
  50. position: int
  51. scheduled_time: UTCDatetime
  52. require_previous_success: bool
  53. auto_off_after: bool
  54. manual_start: bool
  55. ams_mapping: list[int] | None = None
  56. plate_id: int | None = None # Plate ID for multi-plate 3MF files
  57. # Print options
  58. bed_levelling: bool = True
  59. flow_cali: bool = False
  60. vibration_cali: bool = True
  61. layer_inspect: bool = False
  62. timelapse: bool = False
  63. use_ams: bool = True
  64. status: Literal["pending", "printing", "completed", "failed", "skipped", "cancelled"]
  65. started_at: UTCDatetime
  66. completed_at: UTCDatetime
  67. error_message: str | None
  68. created_at: UTCDatetime
  69. # Nested info for UI (populated in route)
  70. archive_name: str | None = None
  71. archive_thumbnail: str | None = None
  72. printer_name: str | None = None
  73. print_time_seconds: int | None = None # Estimated print time from archive
  74. class Config:
  75. from_attributes = True
  76. class PrintQueueReorderItem(BaseModel):
  77. id: int
  78. position: int
  79. class PrintQueueReorder(BaseModel):
  80. items: list[PrintQueueReorderItem]