Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ot_api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import functools

import opentrons.protocol_engine.errors as ot_errors
from opentrons.protocol_engine.errors import ModuleNotLoadedError

import ot_api

Expand Down Expand Up @@ -39,20 +40,21 @@ def get_ot_error(name) -> ot_errors.ProtocolEngineError:
def wrapper(*args, **kwargs):
command_id = f(*args, **kwargs)

# each method supports a `timeout` kwarg
timeout = kwargs.pop("timeout", 30)

end = datetime.datetime.now() + datetime.timedelta(seconds=timeout)
while datetime.datetime.now() < end:
result = ot_api.runs.get_command(command_id, run_id=kwargs["run_id"])

if result["data"]["status"] == "failed":
error_data = result["data"]["error"]
print(error_data)
error_type = error_data["errorType"]
if error_type == "PythonException":
error_class = RuntimeError
else:
error_class = get_ot_error(error_type)

if error_class is ModuleNotLoadedError:
raise ModuleNotLoadedError(error_data["detail"], kwargs["module_id"])
raise error_class(error_data["detail"])
elif result["data"]["status"] in ["queued", "running"]:
continue
Expand Down
36 changes: 36 additions & 0 deletions ot_api/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,39 @@ def temperature_module_deactivate(module_id: str, run_id: str = None):
""" Deactivate a temperature module """
return ot_api.runs.enqueue_command("temperatureModule/deactivate",
{"moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_open_lid(module_id: str, run_id: str = None):
""" Open thermocycler lid """
return ot_api.runs.enqueue_command("thermocycler/openLid",
{"moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_close_lid(module_id: str, run_id: str = None):
""" Close thermocycler lid """
return ot_api.runs.enqueue_command("thermocycler/closeLid",
{"moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_set_block_temperature(celsius: float, module_id: str, run_id: str = None):
""" Set the temperature of a thermocycler block """
return ot_api.runs.enqueue_command("thermocycler/setTargetBlockTemperature",
{"celsius": celsius, "moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_set_lid_temperature(celsius: float, module_id: str, run_id: str = None):
""" Set the temperature of a thermocycler lid """
return ot_api.runs.enqueue_command("thermocycler/setTargetLidTemperature",
{"celsius": celsius, "moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_deactivate_block(module_id: str, run_id: str = None):
""" Deactivate thermocycler block """
return ot_api.runs.enqueue_command("thermocycler/deactivateBlock",
{"moduleId": module_id}, intent="setup", run_id=run_id)

@command
def thermocycler_deactivate_lid(module_id: str, run_id: str = None):
""" Deactivate thermocycler lid """
return ot_api.runs.enqueue_command("thermocycler/deactivateLid",
{"moduleId": module_id}, intent="setup", run_id=run_id)