Skip to content

Commit

Permalink
hook up the error in a few more places
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthecoder committed Nov 22, 2024
1 parent 9edf81c commit 364d45c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
20 changes: 16 additions & 4 deletions api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
from opentrons.protocol_engine.clients import SyncClient as EngineClient
from opentrons.protocols.api_support.definitions import MAX_SUPPORTED_VERSION
from opentrons_shared_data.pipette.types import PipetteNameType
from opentrons_shared_data.errors.exceptions import (
UnsupportedHardwareCommand,
)
from opentrons.protocol_api._nozzle_layout import NozzleLayout
from . import overlap_versions, pipette_movement_conflict

Expand Down Expand Up @@ -85,6 +88,13 @@ def __init__(
self._liquid_presence_detection = bool(
self._engine_client.state.pipettes.get_liquid_presence_detection(pipette_id)
)
if (
self._liquid_presence_detection
and not self._pressure_supported_by_pipette()
):
raise UnsupportedHardwareCommand(
"Pressure sensor not available for this pipette"
)

@property
def pipette_id(self) -> str:
Expand Down Expand Up @@ -859,12 +869,14 @@ def retract(self) -> None:
z_axis = self._engine_client.state.pipettes.get_z_axis(self._pipette_id)
self._engine_client.execute_command(cmd.HomeParams(axes=[z_axis]))

def detect_liquid_presence(self, well_core: WellCore, loc: Location) -> bool:
if not self._sync_hardware_api.pressure_sensor_available(
def _pressure_supported_by_pipette(self) -> bool:
supported = self._sync_hardware_api.pressure_sensor_available(
mount=self.get_mount()
):
raise ValueError("Liquid Presence Detection not available.")
)
assert isinstance(supported, bool)
return supported

def detect_liquid_presence(self, well_core: WellCore, loc: Location) -> bool:
labware_id = well_core.labware_id
well_name = well_core.get_name()
well_location = WellLocation(
Expand Down
4 changes: 4 additions & 0 deletions api/src/opentrons/protocol_api/core/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def get_blow_out_flow_rate(self, rate: float = 1.0) -> float:
def get_liquid_presence_detection(self) -> bool:
...

@abstractmethod
def _pressure_supported_by_pipette(self) -> bool:
...

@abstractmethod
def set_liquid_presence_detection(self, enable: bool) -> None:
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ def liquid_probe_without_recovery(
"""This will never be called because it was added in API 2.20."""
assert False, "liquid_probe_without_recovery only supported in API 2.20 & later"

def _pressure_supported_by_pipette(self) -> bool:
return False

def nozzle_configuration_valid_for_lld(self) -> bool:
"""Check if the nozzle configuration currently supports LLD."""
return False
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ def liquid_probe_without_recovery(
"""This will never be called because it was added in API 2.20."""
assert False, "liquid_probe_without_recovery only supported in API 2.20 & later"

def _pressure_supported_by_pipette(self) -> bool:
return False

def nozzle_configuration_valid_for_lld(self) -> bool:
"""Check if the nozzle configuration currently supports LLD."""
return False
14 changes: 13 additions & 1 deletion api/src/opentrons/protocol_api/instrument_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CommandPreconditionViolated,
CommandParameterLimitViolated,
UnexpectedTipRemovalError,
UnsupportedHardwareCommand,
)
from opentrons.legacy_broker import LegacyBroker
from opentrons.hardware_control.dev_types import PipetteDict
Expand Down Expand Up @@ -259,6 +260,7 @@ def aspirate(
and self._core.nozzle_configuration_valid_for_lld()
and self._core.get_current_volume() == 0
):
self._raise_if_pressure_not_supported_by_pipette()
self.require_liquid_presence(well=well)

with publisher.publish_context(
Expand Down Expand Up @@ -1700,11 +1702,13 @@ def liquid_presence_detection(self) -> bool:
When ``True``, the pipette will check for liquid on every aspiration.
Defaults to ``False``. See :ref:`lpd`.
"""
self._raise_if_pressure_not_supported_by_pipette()
return self._core.get_liquid_presence_detection()

@liquid_presence_detection.setter
@requires_version(2, 20)
def liquid_presence_detection(self, enable: bool) -> None:
self._raise_if_pressure_not_supported_by_pipette()
self._core.set_liquid_presence_detection(enable)

@property
Expand Down Expand Up @@ -2141,6 +2145,7 @@ def detect_liquid_presence(self, well: labware.Well) -> bool:
.. note::
The pressure sensors for the Flex 8-channel pipette are on channels 1 and 8 (positions A1 and H1). For the Flex 96-channel pipette, the pressure sensors are on channels 1 and 96 (positions A1 and H12). Other channels on multi-channel pipettes do not have sensors and cannot detect liquid.
"""
self._raise_if_pressure_not_supported_by_pipette()
loc = well.top()
return self._core.detect_liquid_presence(well._core, loc)

Expand All @@ -2153,6 +2158,7 @@ def require_liquid_presence(self, well: labware.Well) -> None:
.. note::
The pressure sensors for the Flex 8-channel pipette are on channels 1 and 8 (positions A1 and H1). For the Flex 96-channel pipette, the pressure sensors are on channels 1 and 96 (positions A1 and H12). Other channels on multi-channel pipettes do not have sensors and cannot detect liquid.
"""
self._raise_if_pressure_not_supported_by_pipette()
loc = well.top()
self._core.liquid_probe_with_recovery(well._core, loc)

Expand All @@ -2166,7 +2172,7 @@ def measure_liquid_height(self, well: labware.Well) -> float:
This is intended for Opentrons internal use only and is not a guaranteed API.
"""

self._raise_if_pressure_not_supported_by_pipette()
loc = well.top()
height = self._core.liquid_probe_without_recovery(well._core, loc)
return height
Expand All @@ -2187,6 +2193,12 @@ def _raise_if_configuration_not_supported_by_pipette(
)
# SINGLE, QUADRANT and ALL are supported by all pipettes

def _raise_if_pressure_not_supported_by_pipette(self) -> None:
if not self._core._pressure_supported_by_pipette():
raise UnsupportedHardwareCommand(
"Pressure sensor not available for this pipette"
)

def _handle_aspirate_target(
self, target: validation.ValidTarget
) -> tuple[types.Location, Optional[labware.Well], Optional[bool]]:
Expand Down

0 comments on commit 364d45c

Please sign in to comment.