From bd7f541d586de0a3d571bbbce6bee2d29baeb4c7 Mon Sep 17 00:00:00 2001 From: Jeremy Leon Date: Thu, 7 Sep 2023 09:46:12 -0400 Subject: [PATCH] fix(engine): fix labware gripperOffsets not allowing only a default offset (#13472) --- .../protocol_engine/state/labware.py | 10 ++--- .../state/test_labware_view.py | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/api/src/opentrons/protocol_engine/state/labware.py b/api/src/opentrons/protocol_engine/state/labware.py index 80d2c2b6725..80d8a3b6b09 100644 --- a/api/src/opentrons/protocol_engine/state/labware.py +++ b/api/src/opentrons/protocol_engine/state/labware.py @@ -751,8 +751,11 @@ def get_labware_gripper_offsets( """Get the labware's gripper offsets of the specified type.""" parsed_offsets = self.get_definition(labware_id).gripperOffsets offset_key = slot_name.name if slot_name else "default" - return ( - LabwareMovementOffsetData( + + if parsed_offsets is None or offset_key not in parsed_offsets: + return None + else: + return LabwareMovementOffsetData( pickUpOffset=cast( LabwareOffsetVector, parsed_offsets[offset_key].pickUpOffset ), @@ -760,9 +763,6 @@ def get_labware_gripper_offsets( LabwareOffsetVector, parsed_offsets[offset_key].dropOffset ), ) - if parsed_offsets - else None - ) def get_grip_force(self, labware_id: str) -> float: """Get the recommended grip force for gripping labware using gripper.""" diff --git a/api/tests/opentrons/protocol_engine/state/test_labware_view.py b/api/tests/opentrons/protocol_engine/state/test_labware_view.py index 535c2c68694..7d277d93b5a 100644 --- a/api/tests/opentrons/protocol_engine/state/test_labware_view.py +++ b/api/tests/opentrons/protocol_engine/state/test_labware_view.py @@ -10,6 +10,8 @@ Parameters, LabwareRole, OverlapOffset as SharedDataOverlapOffset, + GripperOffsets, + OffsetVector, ) from opentrons.protocols.models import LabwareDefinition from opentrons.types import DeckSlotName, Point, MountType @@ -1346,6 +1348,49 @@ def test_get_labware_gripper_offsets( ) +def test_get_labware_gripper_offsets_default_no_slots( + well_plate_def: LabwareDefinition, + adapter_plate_def: LabwareDefinition, +) -> None: + """It should get the labware's gripper offsets with only a default gripper offset entry.""" + subject = get_labware_view( + labware_by_id={ + "labware-id": LoadedLabware( + id="labware-id", + loadName="labware-load-name", + location=DeckSlotLocation(slotName=DeckSlotName.SLOT_1), + definitionUri="some-labware-uri", + offsetId=None, + displayName="Fancy Labware Name", + ) + }, + definitions_by_uri={ + "some-labware-uri": LabwareDefinition.construct( # type: ignore[call-arg] + gripperOffsets={ + "default": GripperOffsets( + pickUpOffset=OffsetVector(x=1, y=2, z=3), + dropOffset=OffsetVector(x=4, y=5, z=6), + ) + } + ), + }, + ) + + assert ( + subject.get_labware_gripper_offsets( + labware_id="labware-id", slot_name=DeckSlotName.SLOT_D1 + ) + is None + ) + + assert subject.get_labware_gripper_offsets( + labware_id="labware-id", slot_name=None + ) == LabwareMovementOffsetData( + pickUpOffset=LabwareOffsetVector(x=1, y=2, z=3), + dropOffset=LabwareOffsetVector(x=4, y=5, z=6), + ) + + def test_get_grip_force( flex_50uL_tiprack: LabwareDefinition, reservoir_def: LabwareDefinition,