🐛 Fix action command parsing

Introduce two new parameters `name` and `params` for hooks to use.
This commit is contained in:
Gina Häußge committed 2020-09-03 13:12:39 +02:00
1 parent 105078f4b1
commit 98c7fc8197
2 files changed
+19 -10

No files matched your search

+6 -2
View File
@@ -507,7 +507,7 @@ octoprint.comm.protocol.firmware.capabilities
octoprint.comm.protocol.action
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. py:function:: protocol_action_hook(comm_instance, line, action, *args, **kwargs)
.. py:function:: protocol_action_hook(comm_instance, line, action, name='', params='', *args, **kwargs)
React to a :ref:`action command <sec-features-action_commands>` received from the printer.
@@ -534,8 +534,12 @@ octoprint.comm.protocol.action
:param object comm_instance: The :class:`~octoprint.util.comm.MachineCom` instance which triggered the hook.
:param str line: The complete line as received from the printer, format ``// action:<command>``
:param str action: The parsed out action command, so for a ``line`` like ``// action:some_command`` this will be
:param str action: The parsed out action command incl. parameters, so for a ``line`` like ``// action:some_command key value`` this will be
``some_command key value``
:param str name: The action command name, for a ``line`` like ``// action:some_command key value`` this will be
``some_command``
:param str params: The action command's parameter, for a ``line`` like ``// action:some_command key value`` this will
be ``key value``
.. _sec-plugins-hook-comm-protocol-atcommand-phase:
+13 -8
View File
@@ -1761,30 +1761,35 @@ class MachineCom(object):
debugging_output = line[2:].strip()
if debugging_output.startswith("action:"):
action_command = debugging_output[len("action:"):].strip()
action_command_name = action_command.split(' ')[0].strip()
if ' ' in action_command:
action_name, action_params = action_command.split(' ', 1)
action_name = action_name.strip()
else:
action_name = action_command
action_params = ""
if action_command_name == "cancel":
if action_name == "cancel":
self._log("Cancelling on request of the printer...")
self.cancelPrint()
elif action_command_name == "pause":
elif action_name == "pause":
self._log("Pausing on request of the printer...")
self.setPause(True)
elif action_command_name == "paused":
elif action_name == "paused":
self._log("Printer signalled that it paused, switching state...")
self.setPause(True, local_handling=False)
elif action_command_name == "resume":
elif action_name == "resume":
self._log("Resuming on request of the printer...")
self.setPause(False)
elif action_command_name == "resumed":
elif action_name == "resumed":
self._log("Printer signalled that it resumed, switching state...")
self.setPause(False, local_handling=False)
elif action_command_name == "disconnect":
elif action_name == "disconnect":
self._log("Disconnecting on request of the printer...")
self._callback.on_comm_force_disconnect()
else:
for name, hook in self._printer_action_hooks.items():
try:
hook(self, line, action_command)
hook(self, line, action_command, name=action_name, params=action_params)
except Exception:
self._logger.exception("Error while calling hook from plugin "
"{} with action command {}".format(name, action_command),