@@ -125,7 +125,8 @@ def add_plate(
125125 stack : int ,
126126 slot : int ,
127127 plate_id : Optional [str ] = None ,
128- conveyor_child_resource : Optional [Resource ] = None ,
128+ plate_resource : Resource = None ,
129+ current_liconic_resource : Resource = None ,
129130 ) -> None :
130131 """
131132 Updates the liconic inventory file when a new plate is placed into the incubator.
@@ -146,29 +147,30 @@ def add_plate(
146147 # Validations if function is called directly
147148 if not self .is_valid_plate_type (plate_type ): # SHOULD STILL WORK
148149 raise ValueError (f"Unsupported plate type: { plate_type } " )
149- if stack not in self .find_valid_stack (plate_type ):
150+ if stack not in self .find_valid_stack (
151+ plate_type = plate_type ,
152+ resource = current_liconic_resource
153+ ):
150154 raise ValueError (f"Invalid stack { stack } for plate type { plate_type } " )
151- if not self .is_valid_stack_slot (stack , slot ):
155+ if not self .is_valid_stack_slot (
156+ stack = stack ,
157+ slot = slot ,
158+ current_liconic_resource = current_liconic_resource
159+ ):
152160 raise ValueError (
153161 f"Invalid stack/slot combination: stack { stack } , slot { slot } "
154162 )
155- if self .is_location_occupied (stack , slot ):
163+ if self .is_location_occupied (
164+ stack = stack ,
165+ slot = slot ,
166+ current_liconic_resource = current_liconic_resource ,
167+ ):
156168 raise Exception ("Location already occupied" )
157169
158- # Add the plate to the inventory file
159- self .inventory [stack ][slot ] = Slot (
160- occupied = True ,
161- plate_id = plate_id ,
162- time_added = str (datetime .datetime .now ()),
163- )
164- self .update_inventory_file ()
165-
166- # Handle Resource Client calls
167- # Collect conveyor plate resource, if available.
168- conveyor_child_resource = self .resource_client .query_resource (resource_name = f"{ self .node_name } _conveyor.nest" ).child
169170 # Push plate resource onto stack/slot nest resource
170- stack_slot_resource = self .resource_client .query_resource (resource_name = f"{ self .node_name } _stack{ stack } _slot{ slot } .nest" )
171- self .resource_client .push (resource = stack_slot_resource , child = conveyor_child_resource )
171+ stack_resource = current_liconic_resource .children [str (stack )]
172+ slot_resource = stack_resource .children [str (slot )]
173+ self .resource_client .push (resource = slot_resource , child = plate_resource )
172174
173175
174176 def remove_plate (
@@ -216,22 +218,51 @@ def remove_plate(
216218 # Push plate resource onto conveyor resource
217219 self .resource_client .push (resource = conveyor_resource , child = stack_slot_resource_child )
218220
219- def find_plate (self , plate_id : str ) -> tuple [int , int ]:
221+ def find_plate (
222+ self ,
223+ plate_id : str ,
224+ current_liconic_resource : Resource ,
225+ ) -> tuple [int , int ]:
220226 """
221227 Returns the stack and slot a plate is located on, given the plate id
222228
223229 Args:
224230 plate_type (str): name of the plate that matches existing plate definition
231+ current_liconic_resource (Resource): MADSci Resource object representing the current state of the incubator.
225232
226233 Returns:
227234 tuple[int, int]: Tuple with the (stack, slot) location of the plate with the specified plate_id
228235 """
229- for stack_key , stack in self .inventory .stacks .items ():
230- for slot_key , slot in stack .slots .items ():
231- if slot .plate_id == plate_id :
232- return stack_key , slot_key
236+ # TODO: TEST THIS ONce A PLATE WITH A PLATE ID IS ADDED
237+ located_stack = None
238+ located_slot = None
239+ for stack in current_liconic_resource .children :
240+ stack_resource = current_liconic_resource .children [stack ]
241+ for slot in stack_resource .children :
242+ slot_resource = stack_resource .children [slot ]
243+ # TESTING
244+ print (stack )
245+ print (f"\t { slot } " )
246+ if len (slot_resource .children ) == 1 :
247+ print ("slot occupied" )
248+ if slot_resource .children [0 ].attributes ["liconic_plate_id" ] == plate_id :
249+ print ("MATCHING PLATE ID FOUND!" )
250+ located_stack = int (stack )
251+ located_slot = int (slot )
252+ else :
253+ print ("slot empty" )
254+ if located_stack and located_slot :
255+ return (located_stack , located_slot )
233256 raise ValueError ("Plate not found" )
234257
258+
259+
260+ # for stack_key, stack in self.inventory.stacks.items():
261+ # for slot_key, slot in stack.slots.items():
262+ # if slot.plate_id == plate_id:
263+ # return stack_key, slot_key
264+ # raise ValueError("Plate not found")
265+
235266 def get_next_free_slot (
236267 self ,
237268 plate_type : str ,
@@ -291,19 +322,27 @@ def get_next_free_slot(
291322
292323 raise Exception (f"No valid stacks found for plate type '{ plate_type } '" )
293324
294- def is_location_occupied (self , stack : int , slot : int ) -> bool :
325+ def is_location_occupied (
326+ self ,
327+ stack : int ,
328+ slot : int ,
329+ current_liconic_resource : Resource
330+ ) -> bool :
295331 """
296332 Given a stack and slot, determine if the location is occupied
297333
298334 Args:
299335 stack (int): stack number in the incubator
300336 slot (int): slot number in the stack
337+ current_liconic_resource: Resource object for the current incubator state
301338
302339 Returns:
303340 bool: True if location occupied, False otherwise
304341
305342 """
306- return self .inventory [int (stack )][int (slot )].occupied
343+ stack_resource = current_liconic_resource .children [str (stack )]
344+ slot_resource = stack_resource .children [str (slot )]
345+ return len (slot_resource .children ) == 1
307346
308347 def get_plate_id (self , stack : int , slot : int ) -> str :
309348 """
@@ -363,7 +402,12 @@ def is_valid_plate_type(self, plate_type: str) -> bool:
363402 """
364403 return plate_type in self .labware_definitions
365404
366- def is_valid_stack_slot (self , stack : int , slot : int ) -> bool :
405+ def is_valid_stack_slot (
406+ self ,
407+ stack : int ,
408+ slot : int ,
409+ current_liconic_resource : Resource ,
410+ ) -> bool :
367411 """
368412 Checks if the given stack and slot are valid for the current configuration
369413
@@ -375,10 +419,13 @@ def is_valid_stack_slot(self, stack: int, slot: int) -> bool:
375419 bool: True if stack/slot combination is valid for the current configuration, False otherwise
376420 """
377421 valid = True
378- if stack not in self . inventory . stacks :
422+ if str ( stack ) not in current_liconic_resource . children :
379423 valid = False
380- if slot not in self . inventory [ stack ]. slots :
424+ if str ( slot ) not in current_liconic_resource . children [ str ( stack )]. children :
381425 valid = False
426+
427+ # TESTING
428+ print (f"STACK/SLOT COMBO IS VALID?: { valid } " )
382429 return valid
383430
384431
0 commit comments