Browse Source

add command plugin

nico 8 years ago
parent
commit
b31c388ba1
5 changed files with 31 additions and 2 deletions
  1. 15 0
      brain.yml
  2. 1 0
      neurons/__init__.py
  3. 1 0
      neurons/command/__init__.py
  4. 11 0
      neurons/command/command.py
  5. 3 2
      test.py

+ 15 - 0
brain.yml

@@ -18,3 +18,18 @@
     when:
       - order: "quelle heure"
 
+  - name: "Close rolling shutter"
+    neurons:
+      - command: "curl http://192.168.0.22:5000/fermeture -d \"password=monpass\" -X POST"
+      - say: "Fermeture en cours, monsieur"
+    when:
+      - order: "ferme les volets"
+
+  - name: "Open rolling shutter"
+    neurons:
+      - command: "curl http://192.168.0.22:5000/ouverture -d \"password=monpass\" -X POST"
+      - say: "Ouverture en cours, monsieur"
+    when:
+      - order: "ouvre les volets"
+
+

+ 1 - 0
neurons/__init__.py

@@ -1,3 +1,4 @@
 from say import Say
 from systemdate import Systemdate
 from script import Script
+from command import Command

+ 1 - 0
neurons/command/__init__.py

@@ -0,0 +1 @@
+from command import Command

+ 11 - 0
neurons/command/command.py

@@ -0,0 +1,11 @@
+from core import Neurone
+import subprocess
+
+
+class Command(Neurone):
+    def __init__(self, command):
+        Neurone.__init__(self)
+        p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
+        (output, err) = p.communicate()
+
+

+ 3 - 2
test.py

@@ -10,9 +10,10 @@ from core.OrderListener import OrderListener
 # order = "quelle heure est il?"
 
 # test run script
-order = "lance script jarvis"
-
+# order = "lance script jarvis"
 
+# run command
+order = "ferme les volets"
 order_analyser = OrderAnalyser(order)
 
 order_analyser.start()