diff --git a/api/src/opentrons/commands/commands.py b/api/src/opentrons/commands/commands.py index dc3061f6a88..3468c31e531 100755 --- a/api/src/opentrons/commands/commands.py +++ b/api/src/opentrons/commands/commands.py @@ -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={ diff --git a/api/src/opentrons/protocol_api/contexts.py b/api/src/opentrons/protocol_api/contexts.py index 14531f0aeb4..f6e3f1792be 100644 --- a/api/src/opentrons/protocol_api/contexts.py +++ b/api/src/opentrons/protocol_api/contexts.py @@ -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 diff --git a/api/src/opentrons/protocol_api/execute_v1.py b/api/src/opentrons/protocol_api/execute_v1.py index cfe118d84d1..6000cb01a83 100644 --- a/api/src/opentrons/protocol_api/execute_v1.py +++ b/api/src/opentrons/protocol_api/execute_v1.py @@ -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) diff --git a/api/src/opentrons/protocol_api/execute_v3.py b/api/src/opentrons/protocol_api/execute_v3.py index 16a9fd72e18..3f0604904d9 100644 --- a/api/src/opentrons/protocol_api/execute_v3.py +++ b/api/src/opentrons/protocol_api/execute_v3.py @@ -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( diff --git a/api/src/opentrons/protocols/__init__.py b/api/src/opentrons/protocols/__init__.py index 58ac67c7174..c3cb8cfb5f5 100644 --- a/api/src/opentrons/protocols/__init__.py +++ b/api/src/opentrons/protocols/__init__.py @@ -1,5 +1,6 @@ from numpy import add import time +import datetime from itertools import chain from opentrons import instruments, labware, robot @@ -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}" + robot.comment(text) _sleep(wait) elif command_type == 'blowout': diff --git a/api/tests/opentrons/protocol_api/test_execute_v1.py b/api/tests/opentrons/protocol_api/test_execute_v1.py index 8081a66969c..d31faff68c6 100644 --- a/api/tests/opentrons/protocol_api/test_execute_v1.py +++ b/api/tests/opentrons/protocol_api/test_execute_v1.py @@ -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): diff --git a/api/tests/opentrons/protocol_api/test_execute_v3.py b/api/tests/opentrons/protocol_api/test_execute_v3.py index e32852b0008..43fd190482d 100644 --- a/api/tests/opentrons/protocol_api/test_execute_v3.py +++ b/api/tests/opentrons/protocol_api/test_execute_v3.py @@ -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)