Skip to content

Commit

Permalink
type
Browse files Browse the repository at this point in the history
  • Loading branch information
rickwierenga committed Nov 15, 2024
1 parent c09b33c commit 6a35723
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
28 changes: 27 additions & 1 deletion pylabrobot/centrifuge/centrifuge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import cast
from pylabrobot.machines.machine import Machine
from pylabrobot.centrifuge.backend import CentrifugeBackend, LoaderBackend
from pylabrobot.resources.coordinate import Coordinate
from pylabrobot.resources.resource_holder import ResourceHolder
from pylabrobot.serializer import serialize, deserialize


class Centrifuge(Machine):
Expand Down Expand Up @@ -62,7 +64,9 @@ class Loader(Machine, ResourceHolder):
"""The front end for centrifuge loaders.
Centrifuge loaders are devices that can load and unload samples from centrifuges."""

def __init__(self, backend: LoaderBackend, centrifuge: Centrifuge, stage_location: Coordinate) -> None:
def __init__(
self, backend: LoaderBackend, centrifuge: Centrifuge, stage_location: Coordinate
) -> None:
super().__init__(backend=backend)
self.backend: LoaderBackend = backend # fix type
self.centrifuge: Centrifuge = centrifuge
Expand All @@ -80,3 +84,25 @@ async def unload(self) -> None:
if not self.centrifuge.door_open:
raise CentrifugeDoorError("Centrifuge door must be open to unload a plate.")
await self.backend.unload()

def serialize(self) -> dict:
return {
**super().serialize(),
"resource": ResourceHolder.serialize(self),
"machine": Machine.serialize(self),
"centrifuge": self.centrifuge.serialize(),
"stage_location": serialize(self.stage_location),
}

@classmethod
def deserialize(cls, data: dict, allow_marshall: bool = False):
data_copy = data.copy() # copy data because we will be modifying it
centrifuge_data = data_copy.pop("centrifuge")
centrifuge = Centrifuge.deserialize(centrifuge_data)
stage_location_data = data_copy.pop("stage_location")
stage_location = cast(Coordinate, deserialize(stage_location_data))
return cls(
centrifuge=centrifuge,
stage_location=stage_location,
**data_copy,
)
10 changes: 4 additions & 6 deletions pylabrobot/centrifuge/vspin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, centrifuge: "VSpin", device_id: str, timeout: int = 60):
self.dev = Device(lazy_open=True, device_id=device_id)
self.timeout = timeout

async def _read(self):
async def _read(self) -> bytes:
x = b""
r = None
start = time.time()
Expand All @@ -46,10 +46,10 @@ async def _read(self):
raise TimeoutError("No data received within the specified timeout period")
return x

def send_command(self, command: bytes):
async def send_command(self, command: bytes) -> bytes:
logger.debug("[loader] Sending %s", command.hex())
self.dev.write(command)
return self._read()
return await self._read()

async def setup(self):
logger.debug("[loader] setup")
Expand Down Expand Up @@ -137,9 +137,7 @@ class VSpin(CentrifugeBackend):
"""Backend for the Agilent Centrifuge.
Note that this is not a complete implementation."""

def __init__(
self, bucket_1_position: int, device_id: Optional[str] = None, loader: Optional[Loader] = None
):
def __init__(self, bucket_1_position: int, device_id: Optional[str] = None):
"""
Args:
device_id: The libftdi id for the centrifuge. Find using
Expand Down

0 comments on commit 6a35723

Please sign in to comment.