Skip to content

Commit

Permalink
switch to context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Sep 23, 2024
1 parent 4db52f2 commit da050f5
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions api/src/opentrons/protocol_api/instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,12 @@ def mix(
),
):
self.aspirate(volume, location, rate)
if self.api_version >= APIVersion(2, 20):
auto_presence = self.liquid_presence_detection
self.liquid_presence_detection = False
while repetitions - 1 > 0:
self.dispense(volume, rate=rate, **dispense_kwargs)
self.aspirate(volume, rate=rate)
repetitions -= 1
self.dispense(volume, rate=rate)
if self.api_version >= APIVersion(2, 20):
self.liquid_presence_detection = auto_presence
with AutoProbeDisable(self):
while repetitions - 1 > 0:
self.dispense(volume, rate=rate, **dispense_kwargs)
self.aspirate(volume, rate=rate)
repetitions -= 1
self.dispense(volume, rate=rate)
return self

@requires_version(2, 0)
Expand Down Expand Up @@ -2195,6 +2191,22 @@ def _raise_if_configuration_not_supported_by_pipette(
# SINGLE, QUADRANT and ALL are supported by all pipettes


class AutoProbeDisable:
"""Use this class to temporarily disable automatic liquid presence detection."""

def __init__(self, instrument: InstrumentContext):
self.instrument = instrument

def __enter__(self) -> None:
if self.instrument.api_version >= APIVersion(2, 20):
self.auto_presence = self.instrument.liquid_presence_detection
self.instrument.liquid_presence_detection = False

def __exit__(self, *args: Any, **kwargs: Any) -> None:
if self.instrument.api_version >= APIVersion(2, 20):
self.instrument.liquid_presence_detection = self.auto_presence


def _raise_if_has_end_or_front_right_or_back_left(
style: NozzleLayout,
end: Optional[str],
Expand Down

0 comments on commit da050f5

Please sign in to comment.