Skip to content

Commit

Permalink
merged module_state_update with absorbance props
Browse files Browse the repository at this point in the history
  • Loading branch information
TamarZanzouri committed Dec 16, 2024
1 parent c476b6b commit 2baefdf
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 40 deletions.
28 changes: 20 additions & 8 deletions api/src/opentrons/protocol_engine/state/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,25 +601,37 @@ def _handle_absorbance_reader_commands(
configured_wavelengths = absorbance_reader_substate.configured_wavelengths
reference_wavelength = absorbance_reader_substate.reference_wavelength
data = absorbance_reader_substate.data
if state_update.absorbance_reader_lid != update_types.NO_CHANGE:
is_lid_on = state_update.absorbance_reader_lid.is_lid_on
elif state_update.initialize_absorbance_reader_update != update_types.NO_CHANGE:
if (
state_update.module_state_update != update_types.NO_CHANGE
and state_update.module_state_update.absorbance_reader_lid
!= update_types.NO_CHANGE
):
is_lid_on = state_update.module_state_update.absorbance_reader_lid.is_lid_on
elif (
state_update.module_state_update != update_types.NO_CHANGE
and state_update.module_state_update.initialize_absorbance_reader_update
!= update_types.NO_CHANGE
):
module_id = AbsorbanceReaderId(module_id)
configured = True
measured = False
is_lid_on = is_lid_on
measure_mode = AbsorbanceReaderMeasureMode(
state_update.initialize_absorbance_reader_update.measure_mode
state_update.module_state_update.initialize_absorbance_reader_update.measure_mode
)
configured_wavelengths = (
state_update.initialize_absorbance_reader_update.sample_wave_lengths
state_update.module_state_update.initialize_absorbance_reader_update.sample_wave_lengths
)
reference_wavelength = (
state_update.initialize_absorbance_reader_update.reference_wave_length
state_update.module_state_update.initialize_absorbance_reader_update.reference_wave_length
)
data = None
elif state_update.absorbance_reader_data != update_types.NO_CHANGE:
data = state_update.absorbance_reader_data.read_result
elif (
state_update.module_state_update != update_types.NO_CHANGE
and state_update.module_state_update.absorbance_reader_data
!= update_types.NO_CHANGE
):
data = state_update.module_state_update.absorbance_reader_data.read_result
#
# self._state.substate_by_module_id[module_id] = AbsorbanceReaderSubState(
# module_id=AbsorbanceReaderId(module_id),
Expand Down
31 changes: 14 additions & 17 deletions api/src/opentrons/protocol_engine/state/update_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ class PipetteEmptyFluidUpdate:
type: typing.Literal["empty"] = "empty"


@dataclasses.dataclass
class ModuleStateUpdate:
module_id: str
module_type: ModuleType


@dataclasses.dataclass
class AbsorbanceReaderLidUpdate:
"""An update to an absorbance reader's lid location."""
Expand All @@ -277,6 +271,17 @@ class AbsorbanceReaderInitializeUpdate:
reference_wave_length: typing.Optional[int]


@dataclasses.dataclass
class ModuleStateUpdate:
module_id: str
module_type: ModuleType
absorbance_reader_lid: AbsorbanceReaderLidUpdate | NoChangeType = NO_CHANGE
absorbance_reader_data: AbsorbanceReaderDataUpdate | NoChangeType = NO_CHANGE
initialize_absorbance_reader_update: AbsorbanceReaderInitializeUpdate | NoChangeType = (
NO_CHANGE
)


@dataclasses.dataclass
class LiquidClassLoadedUpdate:
"""The state update from loading a liquid class."""
Expand Down Expand Up @@ -333,15 +338,6 @@ class StateUpdate:

liquid_operated: LiquidOperatedUpdate | NoChangeType = NO_CHANGE

absorbance_reader_lid: AbsorbanceReaderLidUpdate | NoChangeType = NO_CHANGE

# this might need to be an array?
absorbance_reader_data: AbsorbanceReaderDataUpdate | NoChangeType = NO_CHANGE

initialize_absorbance_reader_update: AbsorbanceReaderInitializeUpdate | NoChangeType = (
NO_CHANGE
)

module_state_update: ModuleStateUpdate | NoChangeType = NO_CHANGE

liquid_class_loaded: LiquidClassLoadedUpdate | NoChangeType = NO_CHANGE
Expand Down Expand Up @@ -607,9 +603,10 @@ def set_fluid_empty(self: Self, pipette_id: str) -> Self:
def set_absorbance_reader_lid(self: Self, module_id: str, is_lid_on: bool) -> Self:
"""Update an absorbance reader's lid location. See `AbsorbanceReaderLidUpdate`."""
self.module_state_update = ModuleStateUpdate(
module_id=module_id, module_type="absorbanceReaderType"
module_id=module_id,
module_type="absorbanceReaderType",
absorbance_reader_lid=AbsorbanceReaderLidUpdate(is_lid_on=is_lid_on),
)
self.absorbance_reader_lid = AbsorbanceReaderLidUpdate(is_lid_on=is_lid_on)
return self

def set_absorbance_reader_data(
Expand Down
58 changes: 43 additions & 15 deletions api/tests/opentrons/protocol_engine/state/test_update_types.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
"""Unit tests for the utilities in `update_types`."""


from opentrons.protocol_engine import DeckSlotLocation, ModuleLocation
from opentrons.protocol_engine.state import update_types
from opentrons.types import DeckSlotName


def test_append() -> None:
"""Test `StateUpdate.append()`."""
state_update = update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(is_lid_on=True)
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=DeckSlotLocation(slotName=DeckSlotName.SLOT_A1),
offset_id=None,
)
)

# Populating a new field should leave the original ones unchanged.
result = state_update.append(
update_types.StateUpdate(pipette_location=update_types.CLEAR)
)
assert result is state_update
assert state_update.absorbance_reader_lid == update_types.AbsorbanceReaderLidUpdate(
is_lid_on=True
assert state_update.labware_location == update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=DeckSlotLocation(slotName=DeckSlotName.SLOT_A1),
offset_id=None,
)
assert state_update.pipette_location == update_types.CLEAR

# Populating a field that's already been populated should overwrite it.
result = state_update.append(
update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(
is_lid_on=False
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=ModuleLocation(moduleId="module-123"),
offset_id=None,
)
)
)
assert result is state_update
assert state_update.absorbance_reader_lid == update_types.AbsorbanceReaderLidUpdate(
is_lid_on=False
assert state_update.labware_location == update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=ModuleLocation(moduleId="module-123"),
offset_id=None,
)
assert state_update.pipette_location == update_types.CLEAR

Expand All @@ -42,24 +52,42 @@ def test_reduce() -> None:
# It should union all the set fields together.
assert update_types.StateUpdate.reduce(
update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(is_lid_on=True)
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=DeckSlotLocation(slotName=DeckSlotName.SLOT_A1),
offset_id=None,
)
),
update_types.StateUpdate(pipette_location=update_types.CLEAR),
) == update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(is_lid_on=True),
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=DeckSlotLocation(slotName=DeckSlotName.SLOT_A1),
offset_id=None,
),
pipette_location=update_types.CLEAR,
)

# When one field appears multiple times, the last write wins.
assert update_types.StateUpdate.reduce(
update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(is_lid_on=True)
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=DeckSlotLocation(slotName=DeckSlotName.SLOT_A1),
offset_id=None,
)
),
update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(
is_lid_on=False
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=ModuleLocation(moduleId="module-123"),
offset_id=None,
)
),
) == update_types.StateUpdate(
absorbance_reader_lid=update_types.AbsorbanceReaderLidUpdate(is_lid_on=False)
labware_location=update_types.LabwareLocationUpdate(
labware_id="test-123",
new_location=ModuleLocation(moduleId="module-123"),
offset_id=None,
)
)

0 comments on commit 2baefdf

Please sign in to comment.