workpiece.py 816 B

12345678910111213141516171819202122232425262728293031
  1. from dataclasses import dataclass, field
  2. import time
  3. from enum import Enum
  4. class WorkpieceColor(Enum):
  5. NONE = 'NONE'
  6. RED = 'RED'
  7. WHITE = 'WHITE'
  8. BLUE = 'BLUE'
  9. @dataclass
  10. class Workpiece:
  11. id: str
  12. color: WorkpieceColor
  13. state: str = 'RAW'
  14. created_at: float = field(default_factory=time.time) # time when workpiece was created, default to current time, can be set to sim time
  15. def __str__(self):
  16. return f"{type(self).__name__}(id={self.id}, color={self.color.value} state={self.state})"
  17. def __repr__(self):
  18. return f"{type(self).__name__}(id={self.id}, color={self.color.value} state={self.state})"
  19. def to_dict(self) -> dict:
  20. return {
  21. "id": self.id,
  22. "color": self.color.value,
  23. "state": self.state
  24. }