Skip to content

Commit b7a6ff0

Browse files
committed
volume tracker also has a thing attribute
1 parent 430620b commit b7a6ff0

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pylabrobot/resources/container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
)
4242
self._material_z_thickness = material_z_thickness
4343
self.max_volume = max_volume or (size_x * size_y * size_z)
44-
self.tracker = VolumeTracker(max_volume=self.max_volume)
44+
self.tracker = VolumeTracker(thing=f"{self.name}_volume_tracker", max_volume=self.max_volume)
4545
self._compute_volume_from_height = compute_volume_from_height
4646
self._compute_height_from_volume = compute_height_from_volume
4747

pylabrobot/resources/tip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class Tip:
2323
fitting_depth: float
2424

2525
def __post_init__(self):
26-
self.tracker = VolumeTracker(max_volume=self.maximal_volume)
26+
# TODO: use the name
27+
# https://github.com/PyLabRobot/pylabrobot/issues/653
28+
self.tracker = VolumeTracker(thing=f"tip_tracker", max_volume=self.maximal_volume)
2729

2830
def serialize(self) -> dict:
2931
return {

pylabrobot/resources/volume_tracker.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ class VolumeTracker:
6767

6868
def __init__(
6969
self,
70+
thing: str,
7071
max_volume: float,
7172
liquids: Optional[List[Tuple[Optional[Liquid], float]]] = None,
7273
pending_liquids: Optional[List[Tuple[Optional[Liquid], float]]] = None,
7374
liquid_history: Optional[set] = None,
7475
) -> None:
7576
self._is_disabled = False
7677
self._is_cross_contamination_tracking_disabled = False
77-
self.max_volume = max_volume
7878

79+
self.thing = thing
80+
self.max_volume = max_volume
7981
self.liquids: List[Tuple[Optional[Liquid], float]] = liquids or []
8082
self.pending_liquids: List[Tuple[Optional[Liquid], float]] = pending_liquids or []
8183

@@ -123,7 +125,7 @@ def remove_liquid(self, volume: float) -> List[Tuple[Optional["Liquid"], float]]
123125

124126
if volume > self.get_used_volume():
125127
raise TooLittleLiquidError(
126-
f"Container has too little liquid: {volume}uL > {self.get_used_volume()}uL."
128+
f"Container {self.thing} has too little liquid: {volume}uL > {self.get_used_volume()}uL."
127129
)
128130

129131
removed_liquids = []
@@ -149,7 +151,7 @@ def add_liquid(self, liquid: Optional["Liquid"], volume: float) -> None:
149151

150152
if volume > self.get_free_volume():
151153
raise TooLittleVolumeError(
152-
f"Container has too little volume: {volume}uL > {self.get_free_volume()}uL."
154+
f"Container {self.thing} has too little volume: {volume}uL > {self.get_free_volume()}uL."
153155
)
154156

155157
# Update the liquid history tracker if needed
@@ -203,7 +205,7 @@ def get_liquids(self, top_volume: float) -> List[Tuple[Optional[Liquid], float]]
203205

204206
def commit(self) -> None:
205207
"""Commit the pending operations."""
206-
assert not self.is_disabled, "Volume tracker is disabled. Call `enable()`."
208+
assert not self.is_disabled, f"Volume tracker {self.thing} is disabled. Call `enable()`."
207209

208210
self.liquids = copy.deepcopy(self.pending_liquids)
209211

0 commit comments

Comments
 (0)