Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): publish pause and delay commands in python and JSON #3310

Merged
merged 4 commits into from
Apr 11, 2019
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
4 changes: 3 additions & 1 deletion api/src/opentrons/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ def thermocycler_deactivate():
)


def delay(seconds, minutes):
def delay(seconds, minutes, msg=None):
text = "Delaying for {minutes}m {seconds}s"
if msg:
text = f"{text}. {msg}"
return make_command(
name=command_types.DELAY,
payload={
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_api/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def comment(self, msg):
pass

@cmds.publish.both(command=cmds.delay)
def delay(self, seconds=0, minutes=0):
def delay(self, seconds=0, minutes=0, msg=None):
""" Delay protocol execution for a specific amount of time.

:param float seconds: A time to delay in seconds
Expand Down
5 changes: 3 additions & 2 deletions api/src/opentrons/protocol_api/execute_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,14 @@ def dispatch_json(context: ProtocolContext, # noqa(C901)

if command_type == 'delay':
wait = params['wait']
message = params.get('message')
if wait is None:
raise ValueError('Delay cannot be null')
elif wait is True:
message = params.get('message', 'Pausing until user resumes')
message = message or 'Pausing until user resumes'
context.pause(msg=message)
else:
context.delay(seconds=wait)
context.delay(seconds=wait, msg=message)

elif command_type == 'blowout':
well = _get_well(loaded_labware, params)
Expand Down
5 changes: 3 additions & 2 deletions api/src/opentrons/protocol_api/execute_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ def _get_location_with_offset(loaded_labware: Dict[str, labware.Labware],
def _delay(
context, protocol_data, instruments, loaded_labware, params) -> None:
wait = params['wait']
message = params.get('message')
if wait is None or wait is False:
raise ValueError('Delay must be true, or a number')
elif wait is True:
message = params.get('message', 'Pausing until user resumes')
message = message or 'Pausing until user resumes'
context.pause(msg=message)
else:
context.delay(seconds=wait)
context.delay(seconds=wait, msg=message)


def _blowout(
Expand Down
8 changes: 7 additions & 1 deletion api/src/opentrons/protocols/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from numpy import add
import time
import datetime
from itertools import chain
from opentrons import instruments, labware, robot

Expand Down Expand Up @@ -175,12 +176,17 @@ def dispatch_commands(protocol_data, loaded_pipettes, loaded_labware): # noqa:

if command_type == 'delay':
wait = params.get('wait')
message = params.get('message')
if wait is None:
raise ValueError('Delay cannot be null')
elif wait is True:
message = params.get('message', 'Pausing until user resumes')
message = message or 'Pausing until user resumes'
robot.pause(msg=message)
else:
text = f'Delaying for {datetime.timedelta(seconds=wait)}'
if message:
text = f"{text}. {message}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this text var doesn't go anywhere, so APIv1 runs don't give a message for timed delays

robot.comment(text)
_sleep(wait)

elif command_type == 'blowout':
Expand Down
2 changes: 1 addition & 1 deletion api/tests/opentrons/protocol_api/test_execute_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_dispatch_commands(monkeypatch, loop):
cmd = []
flow_rates = []

def mock_sleep(minutes=0, seconds=0):
def mock_sleep(minutes=0, seconds=0, msg=None):
cmd.append(("sleep", minutes * 60 + seconds))

def mock_aspirate(volume, location):
Expand Down
2 changes: 1 addition & 1 deletion api/tests/opentrons/protocol_api/test_execute_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_dispatch_commands(monkeypatch, loop):

ctx = ProtocolContext(loop=loop)

def mock_delay(seconds=0, minutes=0):
def mock_delay(seconds=0, minutes=0, msg=None):
command_log.append(("delay", seconds + minutes * 60))

monkeypatch.setattr(ctx, 'delay', mock_delay)
Expand Down