2
2
3
3
from __future__ import annotations
4
4
5
- from __future__ import annotations
6
5
from typing import Optional , Literal , TYPE_CHECKING , Annotated
7
6
from typing_extensions import Type
8
7
15
14
)
16
15
from ...errors .exceptions import FlexStackerLabwarePoolNotYetDefinedError
17
16
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
+
20
34
21
35
if TYPE_CHECKING :
22
36
from ...state .state import StateView
@@ -74,6 +88,49 @@ class EmptyResult(BaseModel):
74
88
None ,
75
89
description = "The labware definition URI of the lid labware." ,
76
90
)
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
+ )
77
134
78
135
79
136
class EmptyImpl (AbstractCommandImpl [EmptyParams , SuccessData [EmptyResult ]]):
@@ -99,11 +156,42 @@ async def execute(self, params: EmptyParams) -> SuccessData[EmptyResult]:
99
156
100
157
count = params .count if params .count is not None else 0
101
158
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 )
103
185
104
186
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 ,
107
195
)
108
196
)
109
197
@@ -115,28 +203,56 @@ async def execute(self, params: EmptyParams) -> SuccessData[EmptyResult]:
115
203
"The Primary Labware must be defined in the stacker pool."
116
204
)
117
205
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
+
118
224
return SuccessData (
119
- public = EmptyResult (
225
+ public = EmptyResult . model_construct (
120
226
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
125
255
),
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 ,
140
256
),
141
257
state_update = state_update ,
142
258
)
0 commit comments