Skip to content

Commit 5b923a8

Browse files
committed
a couple slight changes
1 parent 5ab5e93 commit 5b923a8

23 files changed

+3826
-1074
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

+144-27
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,35 @@
22

33
from __future__ import annotations
44

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

98
from pydantic import BaseModel, Field
9+
from pydantic.json_schema import SkipJsonSchema
1010

1111
from ..command import AbstractCommandImpl, BaseCommand, BaseCommandCreate, SuccessData
1212
from ...errors import (
1313
ErrorOccurrence,
1414
)
1515
from ...errors.exceptions import FlexStackerLabwarePoolNotYetDefinedError
1616
from ...state import update_types
17-
from ...types import StackerFillEmptyStrategy
18-
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+
1934

2035
if TYPE_CHECKING:
2136
from ...state.state import StateView
@@ -66,14 +81,57 @@ class EmptyResult(BaseModel):
6681
...,
6782
description="The labware definition URI of the primary labware.",
6883
)
69-
adapterLabwareURI: str | None = Field(
84+
adapterLabwareURI: str | SkipJsonSchema[None] = Field(
7085
None,
7186
description="The labware definition URI of the adapter labware.",
7287
)
73-
lidLabwareURI: str | None = Field(
88+
lidLabwareURI: str | SkipJsonSchema[None] = Field(
7489
None,
7590
description="The labware definition URI of the lid labware.",
7691
)
92+
storedLabware: list[StackerStoredLabwareGroup] | SkipJsonSchema[None] = Field(
93+
..., description="The primary labware loaded into the stacker labware pool."
94+
)
95+
removedLabware: list[StackerStoredLabwareGroup] | SkipJsonSchema[None] = Field(
96+
...,
97+
description="The labware objects that have just been removed from the stacker labware pool.",
98+
)
99+
originalPrimaryLabwareLocationSequences: (
100+
list[LabwareLocationSequence] | SkipJsonSchema[None]
101+
) = Field(
102+
None,
103+
description="The previous position of each newly-removed primary labware, in the same order as removedLabware.",
104+
)
105+
originalAdapterLabwareLocationSequences: (
106+
list[LabwareLocationSequence] | SkipJsonSchema[None]
107+
) = Field(
108+
None,
109+
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.",
110+
)
111+
originalLidLabwareLocationSequences: (
112+
list[LabwareLocationSequence] | SkipJsonSchema[None]
113+
) = Field(
114+
None,
115+
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.",
116+
)
117+
newPrimaryLabwareLocationSequences: (
118+
list[LabwareLocationSequence] | SkipJsonSchema[None]
119+
) = Field(
120+
None,
121+
description="The new position of each newly-removed primary labware, in the same order as removedLabware.",
122+
)
123+
newAdapterLabwareLocationSequences: (
124+
list[LabwareLocationSequence] | SkipJsonSchema[None]
125+
) = Field(
126+
None,
127+
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.",
128+
)
129+
newLidLabwareLocationSequences: (
130+
list[LabwareLocationSequence] | SkipJsonSchema[None]
131+
) = Field(
132+
None,
133+
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.",
134+
)
77135

78136

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

100158
count = params.count if params.count is not None else 0
101159

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

104187
state_update = (
105-
update_types.StateUpdate().update_flex_stacker_labware_pool_count(
106-
params.moduleId, new_count
188+
update_types.StateUpdate()
189+
.update_flex_stacker_contained_labware(
190+
module_id=params.moduleId,
191+
contained_labware_bottom_first=new_stored_labware,
192+
)
193+
.set_batch_labware_location(
194+
new_locations_by_id=new_locations_by_id,
195+
new_offset_ids_by_id=new_offset_ids_by_id,
107196
)
108197
)
109198

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

207+
original_locations = [
208+
labware_locations_for_group(
209+
group, [InStackerHopperLocation(moduleId=params.moduleId)]
210+
)
211+
for group in removed_labware
212+
]
213+
new_locations = [
214+
labware_locations_for_group(
215+
group,
216+
[
217+
NotOnDeckLocationSequenceComponent(
218+
logicalLocationName=OFF_DECK_LOCATION
219+
)
220+
],
221+
)
222+
for group in removed_labware
223+
]
224+
118225
return SuccessData(
119-
public=EmptyResult(
226+
public=EmptyResult.model_construct(
120227
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,
228+
primaryLabwareURI=self._state_view.labware.get_uri_from_definition(
229+
stacker_state.pool_primary_definition
230+
),
231+
adapterLabwareURI=self._state_view.labware.get_uri_from_definition_unless_none(
232+
stacker_state.pool_adapter_definition
233+
),
234+
lidLabwareURI=self._state_view.labware.get_uri_from_definition_unless_none(
235+
stacker_state.pool_lid_definition
236+
),
237+
storedLabware=new_stored_labware,
238+
removedLabware=removed_labware,
239+
originalPrimaryLabwareLocationSequences=primary_location_sequences(
240+
original_locations
241+
),
242+
originalAdapterLabwareLocationSequences=adapter_location_sequences_with_default(
243+
original_locations, stacker_state.pool_adapter_definition
244+
),
245+
originalLidLabwareLocationSequences=lid_location_sequences_with_default(
246+
original_locations, stacker_state.pool_lid_definition
247+
),
248+
newPrimaryLabwareLocationSequences=primary_location_sequences(
249+
new_locations
250+
),
251+
newAdapterLabwareLocationSequences=adapter_location_sequences_with_default(
252+
new_locations, stacker_state.pool_adapter_definition
253+
),
254+
newLidLabwareLocationSequences=lid_location_sequences_with_default(
255+
new_locations, stacker_state.pool_lid_definition
125256
),
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,
140257
),
141258
state_update=state_update,
142259
)

0 commit comments

Comments
 (0)