device.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from .cell import Cell
  2. from enum import Enum
  3. class DeviceStatus(Enum):
  4. EMPTY = 0
  5. INSERTED = 1
  6. MEASURING = 2
  7. DONE = 3
  8. ERROR = 4
  9. class Device():
  10. def __init__(self, id: int, config: dict):
  11. """
  12. Initializes a Device instance.
  13. :param device_id: Unique identifier for the device.
  14. :param slots: Number of slots available in the device.
  15. """
  16. self.id: int = id
  17. self.i2c_address: str = config['i2c_address']
  18. self.slots = [Slot(idx) for idx in range(config['num_slots'])]
  19. self.status_list = [DeviceStatus.EMPTY for _ in range(len(self.slots))]
  20. def get_slot_by_id(self, slot_id: int):
  21. return next((slot for slot in self.slots if slot.id == slot_id), None)
  22. class Slot():
  23. def __init__(self, id: int):
  24. self.id = id
  25. self.curr_cell: Cell = None
  26. def insert_cell(self, cell: Cell):
  27. self.curr_cell = cell
  28. def remove_cell(self):
  29. self.curr_cell = None
  30. def is_empty(self) -> bool:
  31. return self.curr_cell is None
  32. def get_cell(self) -> Cell:
  33. return self.curr_cell