Skip to content

Commit d116172

Browse files
committed
a couple slight changes
1 parent fd648bc commit d116172

23 files changed

+3907
-1058
lines changed

api/src/opentrons/protocol_engine/commands/flex_stacker/common.py

+821-2
Large diffs are not rendered by default.

api/src/opentrons/protocol_engine/commands/flex_stacker/empty.py

+141-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
from __future__ import annotations
65
from typing import Optional, Literal, TYPE_CHECKING, Annotated
76
from typing_extensions import Type
87

@@ -15,8 +14,23 @@
1514
)
1615
from ...errors.exceptions import FlexStackerLabwarePoolNotYetDefinedError
1716
from ...state import update_types
18-
from ...types import StackerFillEmptyStrategy
19-
from opentrons.calibration_storage.helpers import uri_from_details
17+
from ...types import (
18+
StackerFillEmptyStrategy,
19+
StackerStoredLabwareGroup,
20+
NotOnDeckLocationSequenceComponent,
21+
OFF_DECK_LOCATION,
22+
InStackerHopperLocation,
23+
LabwareLocationSequence,
24+
OnLabwareLocation,
25+
LabwareLocation,
26+
)
27+
from .common import (
28+
labware_locations_for_group,
29+
primary_location_sequences,
30+
adapter_location_sequences_with_default,
31+
lid_location_sequences_with_default,
32+
)
33+
2034

2135
if TYPE_CHECKING:
2236
from ...state.state import StateView
@@ -74,6 +88,49 @@ class EmptyResult(BaseModel):
7488
None,
7589
description="The labware definition URI of the lid labware.",
7690
)
91+
storedLabware: list[StackerStoredLabwareGroup] | SkipJsonSchema[None] = Field(
92+
..., description="The primary labware loaded into the stacker labware pool."
93+
)
94+
removedLabware: list[StackerStoredLabwareGroup] | SkipJsonSchema[None] = Field(
95+
...,
96+
description="The labware objects that have just been removed from the stacker labware pool.",
97+
)
98+
originalPrimaryLabwareLocationSequences: (
99+
list[LabwareLocationSequence] | SkipJsonSchema[None]
100+
) = Field(
101+
None,
102+
description="The previous position of each newly-removed primary labware, in the same order as removedLabware.",
103+
)
104+
originalAdapterLabwareLocationSequences: (
105+
list[LabwareLocationSequence] | SkipJsonSchema[None]
106+
) = Field(
107+
None,
108+
description="The previous position of each newly-removed adapter labware, in the same order as removedLabware. None if the pool does not specify an adapter.",
109+
)
110+
originalLidLabwareLocationSequences: (
111+
list[LabwareLocationSequence] | SkipJsonSchema[None]
112+
) = Field(
113+
None,
114+
description="The previous position of each newly-removed lid labware, in the same order as removedLabware. None if the pool does not specify a lid.",
115+
)
116+
newPrimaryLabwareLocationSequences: (
117+
list[LabwareLocationSequence] | SkipJsonSchema[None]
118+
) = Field(
119+
None,
120+
description="The new position of each newly-removed primary labware, in the same order as removedLabware.",
121+
)
122+
newAdapterLabwareLocationSequences: (
123+
list[LabwareLocationSequence] | SkipJsonSchema[None]
124+
) = Field(
125+
None,
126+
description="The new position of each newly-removed adapter labware, in the same order as removedLabware. None if the pool does not specify an adapter.",
127+
)
128+
newLidLabwareLocationSequences: (
129+
list[LabwareLocationSequence] | SkipJsonSchema[None]
130+
) = Field(
131+
None,
132+
description="The new position of each newly-removed lid labware, in the same order as removedLabware. None if the pool does not specify a lid labware.",
133+
)
77134

78135

79136
class EmptyImpl(AbstractCommandImpl[EmptyParams, SuccessData[EmptyResult]]):
@@ -99,11 +156,42 @@ async def execute(self, params: EmptyParams) -> SuccessData[EmptyResult]:
99156

100157
count = params.count if params.count is not None else 0
101158

102-
new_count = min(stacker_state.pool_count, count)
159+
new_count = min(len(stacker_state.contained_labware_bottom_first), count)
160+
161+
new_stored_labware = stacker_state.contained_labware_bottom_first[:new_count]
162+
removed_labware = stacker_state.contained_labware_bottom_first[new_count:]
163+
new_locations_by_id: dict[str, LabwareLocation] = {}
164+
new_offset_ids_by_id: dict[str, str | None] = {}
165+
166+
def _add_to_dicts(labware_group: StackerStoredLabwareGroup) -> None:
167+
if labware_group.adapterLabwareId:
168+
new_locations_by_id[labware_group.primaryLabwareId] = OnLabwareLocation(
169+
labwareId=labware_group.adapterLabwareId
170+
)
171+
new_locations_by_id[labware_group.adapterLabwareId] = OFF_DECK_LOCATION
172+
new_offset_ids_by_id[labware_group.primaryLabwareId] = None
173+
new_offset_ids_by_id[labware_group.adapterLabwareId] = None
174+
else:
175+
new_locations_by_id[labware_group.primaryLabwareId] = OFF_DECK_LOCATION
176+
new_offset_ids_by_id[labware_group.primaryLabwareId] = None
177+
if labware_group.lidLabwareId:
178+
new_locations_by_id[labware_group.lidLabwareId] = OnLabwareLocation(
179+
labwareId=labware_group.primaryLabwareId
180+
)
181+
new_offset_ids_by_id[labware_group.lidLabwareId] = None
182+
183+
for group in removed_labware:
184+
_add_to_dicts(group)
103185

104186
state_update = (
105-
update_types.StateUpdate().update_flex_stacker_labware_pool_count(
106-
params.moduleId, new_count
187+
update_types.StateUpdate()
188+
.update_flex_stacker_contained_labware(
189+
module_id=params.moduleId,
190+
contained_labware_bottom_first=new_stored_labware,
191+
)
192+
.set_batch_labware_location(
193+
new_locations_by_id=new_locations_by_id,
194+
new_offset_ids_by_id=new_offset_ids_by_id,
107195
)
108196
)
109197

@@ -115,28 +203,56 @@ async def execute(self, params: EmptyParams) -> SuccessData[EmptyResult]:
115203
"The Primary Labware must be defined in the stacker pool."
116204
)
117205

206+
original_locations = [
207+
labware_locations_for_group(
208+
group, [InStackerHopperLocation(moduleId=params.moduleId)]
209+
)
210+
for group in removed_labware
211+
]
212+
new_locations = [
213+
labware_locations_for_group(
214+
group,
215+
[
216+
NotOnDeckLocationSequenceComponent(
217+
logicalLocationName=OFF_DECK_LOCATION
218+
)
219+
],
220+
)
221+
for group in removed_labware
222+
]
223+
118224
return SuccessData(
119-
public=EmptyResult(
225+
public=EmptyResult.model_construct(
120226
count=new_count,
121-
primaryLabwareURI=uri_from_details(
122-
stacker_state.pool_primary_definition.namespace,
123-
stacker_state.pool_primary_definition.parameters.loadName,
124-
stacker_state.pool_primary_definition.version,
227+
primaryLabwareURI=self._state_view.labware.get_uri_from_definition(
228+
stacker_state.pool_primary_definition
229+
),
230+
adapterLabwareURI=self._state_view.labware.get_uri_from_definition_unless_none(
231+
stacker_state.pool_adapter_definition
232+
),
233+
lidLabwareURI=self._state_view.labware.get_uri_from_definition_unless_none(
234+
stacker_state.pool_lid_definition
235+
),
236+
storedLabware=new_stored_labware,
237+
removedLabware=removed_labware,
238+
originalPrimaryLabwareLocationSequences=primary_location_sequences(
239+
original_locations
240+
),
241+
originalAdapterLabwareLocationSequences=adapter_location_sequences_with_default(
242+
original_locations, stacker_state.pool_adapter_definition
243+
),
244+
originalLidLabwareLocationSequences=lid_location_sequences_with_default(
245+
original_locations, stacker_state.pool_lid_definition
246+
),
247+
newPrimaryLabwareLocationSequences=primary_location_sequences(
248+
new_locations
249+
),
250+
newAdapterLabwareLocationSequences=adapter_location_sequences_with_default(
251+
new_locations, stacker_state.pool_adapter_definition
252+
),
253+
newLidLabwareLocationSequences=lid_location_sequences_with_default(
254+
new_locations, stacker_state.pool_lid_definition
125255
),
126-
adapterLabwareURI=uri_from_details(
127-
stacker_state.pool_adapter_definition.namespace,
128-
stacker_state.pool_adapter_definition.parameters.loadName,
129-
stacker_state.pool_adapter_definition.version,
130-
)
131-
if stacker_state.pool_adapter_definition is not None
132-
else None,
133-
lidLabwareURI=uri_from_details(
134-
stacker_state.pool_lid_definition.namespace,
135-
stacker_state.pool_lid_definition.parameters.loadName,
136-
stacker_state.pool_lid_definition.version,
137-
)
138-
if stacker_state.pool_lid_definition is not None
139-
else None,
140256
),
141257
state_update=state_update,
142258
)

0 commit comments

Comments
 (0)