gcode_macro: implement "action_call_remote_method" context action

Users may use this action to call methods registered by a webhooks client from a command template.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-10-28 08:42:17 -04:00 committed by KevinOConnor
parent 108b66efe9
commit 8a5e7d8d28
1 changed files with 8 additions and 0 deletions

View File

@ -87,12 +87,20 @@ class PrinterGCodeMacro:
return ""
def _action_raise_error(self, msg):
raise self.printer.command_error(msg)
def _action_call_remote_method(self, method, **kwargs):
webhooks = self.printer.lookup_object('webhooks')
try:
webhooks.call_remote_method(method, **kwargs)
except self.printer.command_error:
logging.exception("Remote Call Error")
return ""
def create_template_context(self, eventtime=None):
return {
'printer': GetStatusWrapper(self.printer, eventtime),
'action_emergency_stop': self._action_emergency_stop,
'action_respond_info': self._action_respond_info,
'action_raise_error': self._action_raise_error,
'action_call_remote_method': self._action_call_remote_method,
}
def load_config(config):