diff --git a/api/src/opentrons/protocol_engine/commands/load_liquid.py b/api/src/opentrons/protocol_engine/commands/load_liquid.py index 856cf3ee127..7b68bbaa856 100644 --- a/api/src/opentrons/protocol_engine/commands/load_liquid.py +++ b/api/src/opentrons/protocol_engine/commands/load_liquid.py @@ -3,6 +3,7 @@ from pydantic import BaseModel, Field from typing import Optional, Type, Dict, TYPE_CHECKING from typing_extensions import Literal +from datetime import datetime from .command import AbstractCommandImpl, BaseCommand, BaseCommandCreate, SuccessData from ..errors.error_occurrence import ErrorOccurrence @@ -53,6 +54,19 @@ async def execute( self._state_view.labware.validate_liquid_allowed_in_labware( labware_id=params.labwareId, wells=params.volumeByWell ) + # do this in WellStore?! + labware_id = params.labwareId + well_name = next(iter(params.volumeByWell)) + volume = next(iter(params.volumeByWell.values())) + height = self._state_view.geometry.get_well_height_at_volume( + labware_id=labware_id, well_name=well_name, volume=volume + ) + self._state_view.wells.set_liquid_height( + labware_id=labware_id, + well_name=well_name, + height=height, + time=datetime.now(), + ) return SuccessData(public=LoadLiquidResult(), private=None) diff --git a/api/src/opentrons/protocol_engine/state/geometry.py b/api/src/opentrons/protocol_engine/state/geometry.py index 125be3339a9..fd0359c8771 100644 --- a/api/src/opentrons/protocol_engine/state/geometry.py +++ b/api/src/opentrons/protocol_engine/state/geometry.py @@ -1445,6 +1445,15 @@ def get_well_height_after_volume( target_volume=final_volume, well_geometry=well_geometry ) + def get_well_height_at_volume( + self, labware_id: str, well_name: str, volume: float + ) -> float: + """Convert well volume to height.""" + well_geometry = self._labware.get_well_geometry(labware_id, well_name) + return find_height_at_well_volume( + target_volume=volume, well_geometry=well_geometry + ) + def validate_dispense_volume_into_well( self, labware_id: str, diff --git a/api/src/opentrons/protocol_engine/state/wells.py b/api/src/opentrons/protocol_engine/state/wells.py index d74d94a1be0..04ea9e025f7 100644 --- a/api/src/opentrons/protocol_engine/state/wells.py +++ b/api/src/opentrons/protocol_engine/state/wells.py @@ -127,3 +127,12 @@ def has_measured_liquid_height(self, labware_id: str, well_name: str) -> bool: ) except KeyError: return False + + def set_liquid_height( + self, labware_id: str, well_name: str, height: float, time: datetime + ) -> None: + """Set the liquid height of the well.""" + lhi = LiquidHeightInfo(height=height, last_measured=time) + if labware_id not in self._state.measured_liquid_heights: + self._state.measured_liquid_heights[labware_id] = {} + self._state.measured_liquid_heights[labware_id][well_name] = lhi