Skip to content

Commit

Permalink
MiR: Custom command callback messages (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-Tomas authored Nov 29, 2024
1 parent 0ae9cec commit 1e40532
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 10 additions & 4 deletions mir_connector/inorbit_mir_connector/src/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def _inorbit_command_handler(self, command_name, args, options):
"""
if command_name == COMMAND_CUSTOM_COMMAND:
self._logger.info(f"Received '{command_name}'!. {args}")
if len(args) < 2:
self._logger.error("Invalid number of arguments: ", args)
options["result_function"](
"1", execution_status_details="Invalid number of arguments"
)
return
script_name = args[0]
script_args = args[1]
# TODO (Elvio): Needs to be re designed.
Expand All @@ -139,8 +145,9 @@ def _inorbit_command_handler(self, command_name, args, options):
if script_args[0] == "--state_id":
state_id = script_args[1]
if not state_id.isdigit() or int(state_id) not in MIR_STATE.keys():
self._logger.error(f"Invalid `state_id` ({state_id})")
options["result_function"]("1")
error = f"Invalid `state_id` '{state_id}'"
self._logger.error(error)
options["result_function"]("1", execution_status_details=error)
return
state_id = int(state_id)
self._logger.info(
Expand Down Expand Up @@ -196,9 +203,8 @@ def _inorbit_command_handler(self, command_name, args, options):
self.mir_api.set_state(4)
elif msg == "inorbit_resume":
self.mir_api.set_state(3)

else:
self._logger.info(f"Received '{command_name}'!. {args}")
self._logger.info(f"Received unknown command '{command_name}'!. {args}")

def _connect(self) -> None:
"""Connect to the robot services and to InOrbit"""
Expand Down
8 changes: 6 additions & 2 deletions mir_connector/inorbit_mir_connector/tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ def test_command_callback_state(connector, callback_kwargs):

callback_kwargs["args"] = ["set_state", ["--state_id", "123"]]
connector._inorbit_command_handler(**callback_kwargs)
callback_kwargs["options"]["result_function"].assert_called_with("1")
callback_kwargs["options"]["result_function"].assert_called_with(
"1", execution_status_details="Invalid `state_id` '123'"
)
assert not connector.mir_api.set_state.called

callback_kwargs["args"] = ["set_state", ["--state_id", "abc"]]
connector._inorbit_command_handler(**callback_kwargs)
callback_kwargs["options"]["result_function"].assert_called_with("1")
callback_kwargs["options"]["result_function"].assert_called_with(
"1", execution_status_details="Invalid `state_id` 'abc'"
)
assert not connector.mir_api.set_state.called


Expand Down

0 comments on commit 1e40532

Please sign in to comment.