diff --git a/api/src/opentrons/protocol_engine/state/command_history.py b/api/src/opentrons/protocol_engine/state/command_history.py index 78006605e4c..de16871025b 100644 --- a/api/src/opentrons/protocol_engine/state/command_history.py +++ b/api/src/opentrons/protocol_engine/state/command_history.py @@ -101,17 +101,6 @@ def get_all_ids(self) -> List[str]: """Get all command IDs.""" return self._all_command_ids - def get_filtered_slice( - self, start: int, stop: int, all_commands: bool - ) -> List[Command]: - queued_ids = self.get_filtered_queue_ids( - [CommandIntent.PROTOCOL, CommandIntent.SETUP, CommandIntent.FIXIT] - if all_commands - else [CommandIntent.PROTOCOL, CommandIntent.SETUP] - ) - commands = list(queued_ids)[start:stop] - return [self._commands_by_id[command].command for command in commands] - def get_slice( self, start: int, stop: int, command_ids: Optional[list[str]] = None ) -> List[Command]: @@ -141,21 +130,27 @@ def get_running_command(self) -> Optional[CommandEntry]: else: return self._commands_by_id[self._running_command_id] - def get_filtered_queue_ids( + def get_filtered_command_ids( self, command_intents: list[CommandIntent] = [ CommandIntent.PROTOCOL, CommandIntent.SETUP, ], - ) -> OrderedSet[str]: - queued_ids = self._queued_command_ids + ) -> List[str]: + filtered_command = self._commands_by_id if CommandIntent.FIXIT not in command_intents: - queued_ids = self._queued_command_ids.__sub__( - other=self.get_fixit_queue_ids() - ) + filtered_command = { + key: val + for key, val in self._commands_by_id.items() + if val.command.intent != CommandIntent.FIXIT + } if CommandIntent.SETUP not in command_intents: - queued_ids = queued_ids.__sub__(other=self.get_setup_queue_ids()) - return queued_ids + filtered_command = { + key: val + for key, val in filtered_command.items() + if val.command.intent != CommandIntent.SETUP + } + return list(filtered_command.keys()) def get_queue_ids(self) -> OrderedSet[str]: """Get the IDs of all queued protocol commands, in FIFO order.""" diff --git a/api/src/opentrons/protocol_engine/state/commands.py b/api/src/opentrons/protocol_engine/state/commands.py index 35d19c7a9cb..b0b78372b6f 100644 --- a/api/src/opentrons/protocol_engine/state/commands.py +++ b/api/src/opentrons/protocol_engine/state/commands.py @@ -579,26 +579,6 @@ def get_all(self) -> List[Command]: """ return self._state.command_history.get_all_commands() - def get_filtered_queue_ids(self, all_commands: bool) -> OrderedSet[str]: - """Get a list of all filtered commands in state. - - Entries are returned in the order of first-added command to last-added command. - Replacing a command (to change its status, for example) keeps its place in the - ordering. - - If all_commands is True, retunred list will contain all command intents. - If False, return list will contain only safe commands. - """ - return self._state.command_history.get_filtered_queue_ids( - command_intents=[ - CommandIntent.SETUP, - CommandIntent.PROTOCOL, - CommandIntent.FIXIT, - ] - if all_commands - else [CommandIntent.SETUP, CommandIntent.PROTOCOL] - ) - def get_slice( self, cursor: Optional[int], length: int, all_commands: bool ) -> CommandSlice: @@ -607,7 +587,7 @@ def get_slice( If the cursor is omitted, a cursor will be selected automatically based on the currently running or most recently executed command. """ - queued_command_ids = self._state.command_history.get_filtered_queue_ids( + command_ids = self._state.command_history.get_filtered_command_ids( command_intents=[ CommandIntent.PROTOCOL, CommandIntent.SETUP, @@ -616,7 +596,7 @@ def get_slice( if all_commands else [CommandIntent.PROTOCOL, CommandIntent.SETUP] ) - total_length = len(queued_command_ids) + total_length = len(command_ids) if cursor is None: current_cursor = self.get_current() @@ -638,8 +618,9 @@ def get_slice( # start is inclusive, stop is exclusive actual_cursor = max(0, min(cursor_index, total_length - 1)) stop = min(total_length, actual_cursor + length) - commands = self._state.command_history.get_filtered_slice( - start=actual_cursor, stop=stop, all_commands=all_commands + + commands = self._state.command_history.get_slice( + start=actual_cursor, stop=stop, command_ids=command_ids ) return CommandSlice( diff --git a/api/tests/opentrons/protocol_engine/state/test_command_history.py b/api/tests/opentrons/protocol_engine/state/test_command_history.py index 6ee01c08b0f..bbb8f263277 100644 --- a/api/tests/opentrons/protocol_engine/state/test_command_history.py +++ b/api/tests/opentrons/protocol_engine/state/test_command_history.py @@ -96,7 +96,7 @@ def test_get_all_commands(command_history: CommandHistory) -> None: def test_get_all_filtered_commands(command_history: CommandHistory) -> None: """It should return a list of all commands without fixit commands.""" - assert list(command_history.get_filtered_queue_ids()) == [] + assert list(command_history.get_filtered_command_ids()) == [] command_entry_1 = create_queued_command_entry() command_entry_2 = create_queued_command_entry(index=1) command_history._add("0", command_entry_1) @@ -104,7 +104,7 @@ def test_get_all_filtered_commands(command_history: CommandHistory) -> None: command_history._add_to_queue("0") command_history._add_to_queue("1") command_history._add_to_fixit_queue("1") - assert list(command_history.get_filtered_queue_ids()) == ["0"] + assert list(command_history.get_filtered_command_ids()) == ["0"] def test_get_all_ids(command_history: CommandHistory) -> None: