From 6b5a0f358655d2ee677b0f732a7640831393d233 Mon Sep 17 00:00:00 2001
From: jkerdreu <jkerdreu@b32b6428-25c9-4566-ad07-03861ab6144f>
Date: Thu, 11 Jul 2019 10:08:07 +0000
Subject: [PATCH] =?UTF-8?q?Maj=20apr=C3=A8s=20d=C3=A9mo?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2246 b32b6428-25c9-4566-ad07-03861ab6144f
---
 scripts/ensibs_btn.py | 104 ++++++++++++++++++++++++++++++++----------
 1 file changed, 81 insertions(+), 23 deletions(-)

diff --git a/scripts/ensibs_btn.py b/scripts/ensibs_btn.py
index a566758b..aa5b53de 100644
--- a/scripts/ensibs_btn.py
+++ b/scripts/ensibs_btn.py
@@ -2,10 +2,18 @@ from xaal.lib import Engine
 from xaal.schemas import devices
 from xaal.monitor import Monitor
 import platform
+from functools import partial
 
 PKG_NAME = 'scenario_btn_ensibs'
 
-LAMPS=['aa8cd2e4-8c5d-11e9-b0ba-b827ebe99201']
+LAMPS=['93e09003-708e-11e8-956e-00fec8f7138c','aa8cd2e4-8c5d-11e9-b0ba-b827ebe99201','93e09009-708e-11e8-956e-00fec8f7138c','93e09010-708e-11e8-956e-00fec8f7138c']
+
+MEUBLE_CUIS_UP      = ['93e09080-708e-11e8-956e-00fec8f7138c',]
+MEUBLE_CUIS_DOWN    = ['93e09081-708e-11e8-956e-00fec8f7138c',]
+PLAN_TRAV_CUIS_UP   = ['93e09082-708e-11e8-956e-00fec8f7138c',]
+PLAN_TRAV_CUIS_DOWN = ['93e09083-708e-11e8-956e-00fec8f7138c',]
+
+PRISES_CONNECTEE = ['6265eb30-8c59-11e9-98b1-b827ebe99201',]
 
 # Edisio labo
 EDISIO=['43c06446-8c5c-11e9-a105-b80673742b01','43c06446-8c5c-11e9-a105-b80673742b03','43c06446-8c5c-11e9-a105-b80673742b05',
@@ -16,24 +24,32 @@ AQUARA_1=['fb1f8648-20ba-11e9-b352-a4badbf92500','fb1f8648-20ba-11e9-b352-a4badb
 AQUARA_2=['00796898-20bb-11e9-b352-a4badbf92500','00796898-20bb-11e9-b352-a4badbf92501','00796898-20bb-11e9-b352-a4badbf92502']
 AQUARA_R= '1ec6bbd0-20b5-11e9-b352-a4badbf92500'
 
-SHUTERS=['e4b05165-be5d-46d5-acd0-4da7be1158ed','2fe70f46-3ece-44d1-af34-2d82e10fb854']
+SHUTERS=['93e09051-708e-11e8-956e-00fec8f7138c','93e09050-708e-11e8-956e-00fec8f7138c']
 
-SIREN = ['980a639c-20b1-11e9-8d70-a4badbf92501',]
-PUSH_BULLET=['bc5bb184-8d16-11e9-b4db-9cebe88e1963']
+SIREN= ['980a639c-20b1-11e9-8d70-a4badbf92501',]
+#PUSH_BULLET=['bc5bb184-8d16-11e9-b4db-9cebe88e1963']
+BULLET= ['6eb64b73-6e51-11e9-8f96-00fec8f7138c',]
 
-LAMPS_A = [LAMPS[0]]
+LAMPS_A = [LAMPS[0],LAMPS[1]]
 
 BLINKS = ['aa8cd2e4-8c5d-11e9-b0ba-b827ebe99201','980a639c-20b1-11e9-8d70-a4badbf92500']
 
-RELAYS = ['d34fd5be-8c58-11e9-8999-b827ebe99201']
+#RELAYS = ['d34fd5be-8c58-11e9-8999-b827ebe99201']
 
 mon = None
 dev = None
 
 def send(targets,action,body=None):
     global dev
+    print("Sending %s %s" % (targets,action))
     dev.engine.send_request(dev,targets,action,body)
 
+def delayed_send(delay,targets,action,body=None):
+    global dev
+    engine = dev.engine
+    func = partial(send,targets=targets,action=action,body=None)
+    engine.add_timer(func,delay,1)
+    
 def search_for_light(lamps):
     for l in lamps:
         dev = mon.devices.get_with_addr(l)
@@ -58,8 +74,10 @@ def siren_play(snd=2):
 def siren_stop():
     send(SIREN,'stop')
 
-def pushbullet(title,msg):
-    send(PUSH_BULLET,'notify',{'title': title,'msg':msg})
+#def pushbullet(title,msg):
+    #send(BULLET,'notify',{'title': title,'msg':msg})
+def pushbullet():
+    send(BULLET,'notify',{'title':'Alerte','msg':"Appel secour"})
 
 def blink():
     send(BLINKS,'blink')
@@ -73,27 +91,67 @@ def handle_msg(msg):
         if msg.source == AQUARA_R:
             blink()
             siren_play(2)
-            pushbullet('Alerte','')
+            #pushbullet('Alerte','')
+            pushbullet()
 
         if msg.source == AQUARA_1[0]:
-            #on_off_light(LAMPS_A)
-            send(RELAYS,'on')
-
+            send(MEUBLE_CUIS_DOWN,'on')
+            delayed_send(6,MEUBLE_CUIS_DOWN,'off')
+            send(PLAN_TRAV_CUIS_DOWN,'on')
+            delayed_send(8,PLAN_TRAV_CUIS_DOWN,'off')
+        
         if msg.source == AQUARA_1[1]:
             #on_off_light(LAMPS_A)
-            send(RELAYS,'off')
-
-        if msg.source == AQUARA_2[0]: 
-            siren_play(20)
-
-        if msg.source == AQUARA_2[1]: 
-            pushbullet('Alerte','Intrusion')
-            siren_play(1)
+            #send(RELAYS,'on')
+            #on_off_light(LAMPS)
+            send(MEUBLE_CUIS_UP,'on')
+            delayed_send(6,MEUBLE_CUIS_UP,'off')
+            send(PLAN_TRAV_CUIS_UP,'on')
+            delayed_send(8,PLAN_TRAV_CUIS_UP,'off')
+        
+        if msg.source == AQUARA_1[2]:
+            send(MEUBLE_CUIS_DOWN,'off')
+            send(PLAN_TRAV_CUIS_DOWN,'off')
+            send(MEUBLE_CUIS_UP,'off')
+            send(PLAN_TRAV_CUIS_UP,'off')
+            
+        if msg.source == AQUARA_2[0]:
+            #send(LAMPS,'on')
+            delayed_send(5,[LAMPS[0],],'on')
+            delayed_send(5,[LAMPS[3],],'on')
+            delayed_send(10,[LAMPS[1],],'on')
+            delayed_send(10,[LAMPS[2],],'on')
+            send(SHUTERS,'down')
+            #delayed_send(10,SHUTERS,'stop')
+            delayed_send(15,PRISES_CONNECTEE,'on')
+
+        if msg.source == AQUARA_2[1]:
+            send(SHUTERS,'up')
+            #send(LAMPS,'off')
+            #delayed_send(5,LAMPS,'off')
+            delayed_send(20,[LAMPS[1],],'off')
+            delayed_send(20,[LAMPS[2],],'off')
+            delayed_send(25,[LAMPS[0],],'off')
+            delayed_send(25,[LAMPS[3],],'off')
+            delayed_send(15,PRISES_CONNECTEE,'off')
 
         if msg.source == AQUARA_2[2]:
-            siren_stop()
-
-            #send(SHUTERS,'stop')
+            send(SHUTERS,'stop')
+        
+        if msg.source == EDISIO[0]:
+            send([SHUTERS[0],],'up')
+        
+        if msg.source == EDISIO[1]:
+            send([SHUTERS[1],],'up')
+        
+        if msg.source == EDISIO[2]:
+            send(SHUTERS,'stop')
+        
+        if msg.source == EDISIO[3]:
+            send([SHUTERS[0],],'down')
+        
+        if msg.source == EDISIO[4]:
+            send([SHUTERS[1],],'down')
 
                 
 def main():
-- 
GitLab