spoolbuddy.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. from datetime import datetime
  2. from pydantic import BaseModel, Field
  3. # --- Device schemas ---
  4. class DeviceRegisterRequest(BaseModel):
  5. device_id: str = Field(..., min_length=1, max_length=50)
  6. hostname: str = Field(..., min_length=1, max_length=100)
  7. ip_address: str = Field(..., min_length=1, max_length=45)
  8. firmware_version: str | None = None
  9. has_nfc: bool = True
  10. has_scale: bool = True
  11. tare_offset: int = 0
  12. calibration_factor: float = 1.0
  13. nfc_reader_type: str | None = None
  14. nfc_connection: str | None = None
  15. has_backlight: bool = False
  16. class DeviceResponse(BaseModel):
  17. id: int
  18. device_id: str
  19. hostname: str
  20. ip_address: str
  21. firmware_version: str | None = None
  22. has_nfc: bool
  23. has_scale: bool
  24. tare_offset: int
  25. calibration_factor: float
  26. nfc_reader_type: str | None = None
  27. nfc_connection: str | None = None
  28. display_brightness: int = 100
  29. display_blank_timeout: int = 0
  30. has_backlight: bool = False
  31. last_calibrated_at: datetime | None = None
  32. last_seen: datetime | None = None
  33. pending_command: str | None = None
  34. nfc_ok: bool
  35. scale_ok: bool
  36. uptime_s: int
  37. online: bool = False
  38. created_at: datetime
  39. updated_at: datetime
  40. class Config:
  41. from_attributes = True
  42. class HeartbeatRequest(BaseModel):
  43. nfc_ok: bool = False
  44. scale_ok: bool = False
  45. uptime_s: int = 0
  46. firmware_version: str | None = None
  47. ip_address: str | None = None
  48. nfc_reader_type: str | None = None
  49. nfc_connection: str | None = None
  50. class HeartbeatResponse(BaseModel):
  51. pending_command: str | None = None
  52. tare_offset: int
  53. calibration_factor: float
  54. display_brightness: int = 100
  55. display_blank_timeout: int = 0
  56. # --- NFC schemas ---
  57. class TagScannedRequest(BaseModel):
  58. device_id: str
  59. tag_uid: str
  60. tray_uuid: str | None = None
  61. sak: int | None = None
  62. tag_type: str | None = None
  63. raw_blocks: dict | None = None
  64. class TagRemovedRequest(BaseModel):
  65. device_id: str
  66. tag_uid: str
  67. # --- Scale schemas ---
  68. class ScaleReadingRequest(BaseModel):
  69. device_id: str
  70. weight_grams: float
  71. stable: bool = False
  72. raw_adc: int | None = None
  73. class UpdateSpoolWeightRequest(BaseModel):
  74. spool_id: int
  75. weight_grams: float
  76. # --- Calibration schemas ---
  77. class TareRequest(BaseModel):
  78. pass
  79. class SetTareRequest(BaseModel):
  80. tare_offset: int
  81. class SetCalibrationFactorRequest(BaseModel):
  82. known_weight_grams: float = Field(..., gt=0)
  83. raw_adc: int
  84. tare_raw_adc: int | None = None
  85. class CalibrationResponse(BaseModel):
  86. tare_offset: int
  87. calibration_factor: float
  88. # --- Display schemas ---
  89. class DisplaySettingsRequest(BaseModel):
  90. brightness: int = Field(ge=0, le=100)
  91. blank_timeout: int = Field(ge=0)