Skip to content

Commit

Permalink
Revert "Combine _set_load_pipette() and _update_pipette_config()"
Browse files Browse the repository at this point in the history
This reverts commit cb1f6396bdd851d4e61fbaadf93fef12a78e9cb0.
  • Loading branch information
SyntaxColoring committed Oct 14, 2024
1 parent d4f782e commit 07153b8
Showing 1 changed file with 51 additions and 56 deletions.
107 changes: 51 additions & 56 deletions api/src/opentrons/protocol_engine/state/pipettes.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def handle_action(self, action: Action) -> None:
"""Modify state in reaction to an action."""
state_update = get_state_update(action)
if state_update is not None:
self._load_pipette_or_update_config(state_update)
self._set_load_pipette(state_update)
self._update_current_location(state_update)
self._update_pipette_config(state_update)
self._update_pipette_nozzle_map(state_update)
self._update_tip_state(state_update)

Expand All @@ -154,52 +155,7 @@ def handle_action(self, action: Action) -> None:
elif isinstance(action, SetPipetteMovementSpeedAction):
self._state.movement_speed_by_id[action.pipette_id] = action.speed

def _load_pipette_or_update_config(
self, state_update: update_types.StateUpdate
) -> None:
if state_update.pipette_config != update_types.NO_CHANGE:
config = state_update.pipette_config.config
self._state.static_config_by_id[
state_update.pipette_config.pipette_id
] = StaticPipetteConfig(
serial_number=state_update.pipette_config.serial_number,
model=config.model,
display_name=config.display_name,
min_volume=config.min_volume,
max_volume=config.max_volume,
channels=config.channels,
tip_configuration_lookup_table=config.tip_configuration_lookup_table,
nominal_tip_overlap=config.nominal_tip_overlap,
home_position=config.home_position,
nozzle_offset_z=config.nozzle_offset_z,
pipette_bounding_box_offsets=PipetteBoundingBoxOffsets(
back_left_corner=config.back_left_corner_offset,
front_right_corner=config.front_right_corner_offset,
back_right_corner=Point(
config.front_right_corner_offset.x,
config.back_left_corner_offset.y,
config.back_left_corner_offset.z,
),
front_left_corner=Point(
config.back_left_corner_offset.x,
config.front_right_corner_offset.y,
config.back_left_corner_offset.z,
),
),
bounding_nozzle_offsets=BoundingNozzlesOffsets(
back_left_offset=config.nozzle_map.back_left_nozzle_offset,
front_right_offset=config.nozzle_map.front_right_nozzle_offset,
),
default_nozzle_map=config.nozzle_map,
lld_settings=config.pipette_lld_settings,
)
self._state.flow_rates_by_id[
state_update.pipette_config.pipette_id
] = config.flow_rates
self._state.nozzle_configuration_by_id[
state_update.pipette_config.pipette_id
] = config.nozzle_map

def _set_load_pipette(self, state_update: update_types.StateUpdate) -> None:
if state_update.loaded_pipette != update_types.NO_CHANGE:
pipette_id = state_update.loaded_pipette.pipette_id

Expand All @@ -214,15 +170,10 @@ def _load_pipette_or_update_config(
self._state.aspirated_volume_by_id[pipette_id] = None
self._state.movement_speed_by_id[pipette_id] = None
self._state.attached_tip_by_id[pipette_id] = None

# This should always be truthy because LoadPipetteImplementation always
# supplies state_update.pipette_config, which we process above,
# populating self._state.static_config_by_id[pipette_id].
#
# todo(mm, 2024-10-14): Formalize this expectation by having
# state_update.loaded_pipette incorporate all the stuff in
# state_update.pipette_config, so LoadPipetteImplementation only has to
# supply state_update.loaded_pipette.
# TODO(mm, 2024-10-11): This seems wrong--because of the order in which
# we process the individual attributes of StateUpdate, when we process a
# loadPipette command, won't we always reach here before static_config is
# populated?
static_config = self._state.static_config_by_id.get(pipette_id)
if static_config:
self._state.nozzle_configuration_by_id[
Expand Down Expand Up @@ -315,6 +266,50 @@ def _update_current_location(self, state_update: update_types.StateUpdate) -> No
mount=loaded_pipette.mount, deck_point=new_deck_point
)

def _update_pipette_config(self, state_update: update_types.StateUpdate) -> None:
if state_update.pipette_config != update_types.NO_CHANGE:
config = state_update.pipette_config.config
self._state.static_config_by_id[
state_update.pipette_config.pipette_id
] = StaticPipetteConfig(
serial_number=state_update.pipette_config.serial_number,
model=config.model,
display_name=config.display_name,
min_volume=config.min_volume,
max_volume=config.max_volume,
channels=config.channels,
tip_configuration_lookup_table=config.tip_configuration_lookup_table,
nominal_tip_overlap=config.nominal_tip_overlap,
home_position=config.home_position,
nozzle_offset_z=config.nozzle_offset_z,
pipette_bounding_box_offsets=PipetteBoundingBoxOffsets(
back_left_corner=config.back_left_corner_offset,
front_right_corner=config.front_right_corner_offset,
back_right_corner=Point(
config.front_right_corner_offset.x,
config.back_left_corner_offset.y,
config.back_left_corner_offset.z,
),
front_left_corner=Point(
config.back_left_corner_offset.x,
config.front_right_corner_offset.y,
config.back_left_corner_offset.z,
),
),
bounding_nozzle_offsets=BoundingNozzlesOffsets(
back_left_offset=config.nozzle_map.back_left_nozzle_offset,
front_right_offset=config.nozzle_map.front_right_nozzle_offset,
),
default_nozzle_map=config.nozzle_map,
lld_settings=config.pipette_lld_settings,
)
self._state.flow_rates_by_id[
state_update.pipette_config.pipette_id
] = config.flow_rates
self._state.nozzle_configuration_by_id[
state_update.pipette_config.pipette_id
] = config.nozzle_map

def _update_pipette_nozzle_map(
self, state_update: update_types.StateUpdate
) -> None:
Expand Down

0 comments on commit 07153b8

Please sign in to comment.