summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2016-07-17 23:33:18 +1200
committerFlorian Baumann <derflob@derflob.de>2016-07-19 08:57:34 +1200
commit92f10603b84ed68437a9d107498fed859b1cff85 (patch)
tree04d8900510a46bf64c8987da69883b09af29707c
parent6952ba1791f322404940e67c63e9aa8779f74b58 (diff)
downloadxmpp-92f10603b84ed68437a9d107498fed859b1cff85.tar.gz
xmpp-92f10603b84ed68437a9d107498fed859b1cff85.tar.bz2
Control 433MHz sockets
add commands: * all systems <go|stop> * power <on|off> * lights <on|off>
-rw-r--r--__init__.py54
-rw-r--r--rcswitch.py22
2 files changed, 75 insertions, 1 deletions
diff --git a/__init__.py b/__init__.py
index 31fb850..a4c4c72 100644
--- a/__init__.py
+++ b/__init__.py
@@ -5,6 +5,7 @@ import io
import requests
import sleekxmpp
import datetime
+import subprocess
from octoprint.plugin import EventHandlerPlugin, SettingsPlugin
@@ -373,9 +374,60 @@ class OctoXMPP(EventHandlerPlugin, SettingsPlugin):
msg.reply(body="\n".join(lines)).send()
+ @xmpp_cmd("all systems <go|stop>")
+ def _cmd_all(self, msg, system, action):
+ m = re.match(r'[a-zA-Z]+', action)
+ if (not m):
+ return self._cmd_help(msg, 'all')
+ else:
+ action = m.group(0)
+
+ if (system == "systems"):
+ if (action.lower() in ['go', 'start']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "10000", "--on"])
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "01000", "--on"])
+ elif (action.lower() in ['halt', 'stop']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "10000", "--off"])
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "01000", "--off"])
+ else:
+ return self._cmd_help(msg, 'all')
+ else:
+ return self._cmd_help(msg, 'all')
+
+ @xmpp_cmd("lights <on|off>")
+ def _cmd_lights(self, msg, action):
+ m = re.match(r'[a-zA-Z]+', action)
+ if (not m):
+ return self._cmd_help(msg, 'lights')
+ else:
+ action = m.group(0)
+
+ if (action.lower() in ['on', 'start', 'up']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "10000", "--on"])
+ elif (action.lower() in ['off', 'stop', 'down']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "10000", "--off"])
+ else:
+ return self._cmd_help(msg, 'lights')
+
+
+ @xmpp_cmd("power <on|off>")
+ def _cmd_power(self, msg, action):
+ m = re.match(r'[a-zA-Z]+', action)
+ if (not m):
+ return self._cmd_help(msg, power)
+ else:
+ action = m.group(0)
+
+ if (action.lower() in ['on', 'start', 'up']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "01000", "--on"])
+ elif (action.lower() in ['off', 'stop', 'down']):
+ subprocess.call(["sudo", "/home/pi/oprint/bin/python", "/home/pi/.octoprint/plugins/OctoXMPP/rcswitch.py", "00111", "01000", "--off"])
+ else:
+ return self._cmd_help(msg, 'power')
+
__plugin_name__ = "OctoXMPP"
-__plugin_version__ = "0.2.2"
+__plugin_version__ = "0.2.3"
__plugin_description__ = "Control OctoPrint via XMPP messages."
__plugin_implementation__ = OctoXMPP()
diff --git a/rcswitch.py b/rcswitch.py
new file mode 100644
index 0000000..b51c2ab
--- /dev/null
+++ b/rcswitch.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import pi_switch
+import argparse
+
+if (__name__ == "__main__"):
+ parser = argparse.ArgumentParser()
+ parser.add_argument('channel', type=str)
+ parser.add_argument('group', type=str)
+
+ action = parser.add_mutually_exclusive_group(required=True)
+ action.add_argument('--on', action='store_true')
+ action.add_argument('--off', action='store_true')
+
+ args = parser.parse_args()
+ sw = pi_switch.RCSwitchA(args.channel, args.group)
+ sw.enableTransmit(0)
+ if (args.on):
+ sw.switchOn()
+ elif (args.off):
+ sw.switchOff()
+ else:
+ sw.switchOff()