summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2016-07-16 13:55:04 +1200
committerFlorian Baumann <derflob@derflob.de>2016-07-16 23:39:04 +1200
commit6952ba1791f322404940e67c63e9aa8779f74b58 (patch)
tree673626d3ae95978864b68b078ddcc209232ae82a
parent1e4f0d0c45534367a23c031870e08a41815b80ef (diff)
downloadxmpp-6952ba1791f322404940e67c63e9aa8779f74b58.tar.gz
xmpp-6952ba1791f322404940e67c63e9aa8779f74b58.tar.bz2
cmd help
-rw-r--r--__init__.py55
1 files changed, 54 insertions, 1 deletions
diff --git a/__init__.py b/__init__.py
index 81403fc..31fb850 100644
--- a/__init__.py
+++ b/__init__.py
@@ -8,6 +8,30 @@ import datetime
from octoprint.plugin import EventHandlerPlugin, SettingsPlugin
+class xmpp_cmd():
+
+ def __init__(self, usage, name=None, desc=None, hidden=False):
+ self.usage = usage
+ self.name = name
+ self.desc = desc
+ self.hidden = hidden
+
+ def __call__(self, fn):
+ fn.usage = self.usage
+
+ if (self.name):
+ fn.xmpp_cmd = self.name
+ else:
+ fn.xmpp_cmd = fn.__name__[len('_cmd_'):]
+
+ if (self.desc):
+ fn.desc = self.desc
+ else:
+ fn.desc = fn.__doc__
+
+ fn.hidden = self.hidden
+
+ return fn
class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
@@ -130,6 +154,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
fn(msg, *cmd_args)
+ @xmpp_cmd("", hidden=True)
def __cmd_unknown(self, cmd):
def __cmd_unknown_reply(msg, *args):
reply = msg.reply(body="Unknown command '{}' ({})!".format(cmd, ", ".join(args)))
@@ -137,6 +162,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
return __cmd_unknown_reply
+ @xmpp_cmd("status <temp|job|machine|all>")
def _cmd_status(self, msg, subsystem='all'):
subsystems = ['temp', 'job', 'machine']
@@ -215,6 +241,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
def _status_state(self):
return "{}".format(self._printer.get_current_data())
+ @xmpp_cmd("snapshot")
def _cmd_snapshot(self, msg):
(snapshot, content_type) = self._take_snapshot()
if (snapshot):
@@ -229,6 +256,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
self._xmpp.add_event_handler("http_upload::{}::finished".format(i),
__send_get_url, disposable=True)
+ @xmpp_cmd("job <start|pause|resume|cancel>")
def _cmd_job(self, msg, action=None):
actions = ['start', 'pause', 'resume', 'cancel', 'abort']
job = self._printer.get_current_job()
@@ -274,6 +302,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
def _job_abort(self):
return self._job_cancel()
+ @xmpp_cmd("home (<x|y|z|e>)*|<all>")
def _cmd_home(self, msg, *axis):
axes = list(filter(lambda a: a in ('all', ) + self._printer.valid_axes, axis))
if (len(axes) == 0):
@@ -287,6 +316,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
self._printer.home(axes)
msg.reply(body=reply).send()
+ @xmpp_cmd("temp <toolN|bed> <temperature>")
def _cmd_temp(self, msg, dev, temp):
if (not self._printer.valid_heater_regex.match(dev)):
reply = "Invalid heater name! It must match '{}'!".format(
@@ -297,6 +327,7 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
msg.reply(body=reply).send()
+ @xmpp_cmd("move (<x|y|z|e|f><position>)*")
def _cmd_move(self, msg, *coords):
if (self._printer.is_operational()):
if (self._printer.is_printing() and not self._printer.is_paused()):
@@ -320,9 +351,31 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
msg.reply(body=reply).send()
+ @xmpp_cmd("help <command|all>")
+ def _cmd_help(self, msg, *cmd):
+ lines = []
+ if (len(cmd) == 0 or cmd[0] == 'all'):
+ lines.append("Available commands:")
+ for attr in dir(self):
+ fn = getattr(self, attr)
+ if (hasattr(fn, 'xmpp_cmd') and not fn.hidden):
+ lines.append("{} - {}".format(fn.xmpp_cmd, fn.usage))
+ if (fn.desc):
+ lines.append("* {}\n".format(fn.desc))
+ else:
+ fn = getattr(self, "_cmd_{}".format(cmd[0]), None)
+ if (fn and hasattr(fn, 'xmpp_cmd')):
+ lines.append("{} - {}".format(fn.xmpp_cmd, fn.usage))
+ if (fn.desc):
+ lines.append("* {}".format(fn.desc))
+ else:
+ lines.append("{} not an available command.".format(cmd[0]))
+
+ msg.reply(body="\n".join(lines)).send()
+
__plugin_name__ = "OctoXMPP"
-__plugin_version__ = "0.2.1"
+__plugin_version__ = "0.2.2"
__plugin_description__ = "Control OctoPrint via XMPP messages."
__plugin_implementation__ = OctoXMPP()