From 884b27728b19f44a063a1a8f24edc25904f1ce3a Mon Sep 17 00:00:00 2001 From: vegano1 Date: Thu, 24 Oct 2024 17:58:12 -0400 Subject: [PATCH] fix(api): raise CannotPerformModuleAction if the plate reader is initialized before calling close_lid. --- .../protocol_api/core/engine/module_core.py | 7 +++++++ .../core/engine/test_absorbance_reader_core.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/api/src/opentrons/protocol_api/core/engine/module_core.py b/api/src/opentrons/protocol_api/core/engine/module_core.py index 9f2785b7432..1e6d4e26b2f 100644 --- a/api/src/opentrons/protocol_api/core/engine/module_core.py +++ b/api/src/opentrons/protocol_api/core/engine/module_core.py @@ -567,6 +567,7 @@ class AbsorbanceReaderCore(ModuleCore, AbstractAbsorbanceReaderCore): _sync_module_hardware: SynchronousAdapter[hw_modules.AbsorbanceReader] _initialized_value: Optional[List[int]] = None + _ready_to_initialize: bool = False def initialize( self, @@ -575,6 +576,11 @@ def initialize( reference_wavelength: Optional[int] = None, ) -> None: """Initialize the Absorbance Reader by taking zero reading.""" + if not self._ready_to_initialize: + raise CannotPerformModuleAction( + "Cannot perform Initialize action on Absorbance Reader without calling `.close_lid()` first." + ) + # TODO: check that the wavelengths are within the supported wavelengths self._engine_client.execute_command( cmd.absorbance_reader.InitializeParams( @@ -633,6 +639,7 @@ def close_lid( moduleId=self.module_id, ) ) + self._ready_to_initialize = True def open_lid(self) -> None: """Close the Absorbance Reader's lid.""" diff --git a/api/tests/opentrons/protocol_api/core/engine/test_absorbance_reader_core.py b/api/tests/opentrons/protocol_api/core/engine/test_absorbance_reader_core.py index a5fadde09cc..a9879e4ee94 100644 --- a/api/tests/opentrons/protocol_api/core/engine/test_absorbance_reader_core.py +++ b/api/tests/opentrons/protocol_api/core/engine/test_absorbance_reader_core.py @@ -11,6 +11,7 @@ from opentrons.protocol_engine.clients import SyncClient as EngineClient from opentrons.protocol_api.core.engine.module_core import AbsorbanceReaderCore from opentrons.protocol_api import MAX_SUPPORTED_VERSION +from opentrons.protocol_engine.errors.exceptions import CannotPerformModuleAction from opentrons.protocol_engine.state.module_substates import AbsorbanceReaderSubState from opentrons.protocol_engine.state.module_substates.absorbance_reader_substate import ( AbsorbanceReaderId, @@ -67,6 +68,7 @@ def test_initialize( decoy: Decoy, mock_engine_client: EngineClient, subject: AbsorbanceReaderCore ) -> None: """It should set the sample wavelength with the engine client.""" + subject._ready_to_initialize = True subject.initialize("single", [123]) decoy.verify( @@ -115,10 +117,20 @@ def test_initialize( assert subject._initialized_value == [124, 125, 126] +def test_initialize_not_ready( + subject: AbsorbanceReaderCore +) -> None: + """It should raise CannotPerformModuleAction if you dont call .close_lid() command.""" + subject._ready_to_initialize = False + with pytest.raises(CannotPerformModuleAction): + subject.initialize("single", [123]) + + def test_read( decoy: Decoy, mock_engine_client: EngineClient, subject: AbsorbanceReaderCore ) -> None: """It should call absorbance reader to read with the engine client.""" + subject._ready_to_initialize = True subject._initialized_value = [123] substate = AbsorbanceReaderSubState( module_id=AbsorbanceReaderId(subject.module_id),