From 2f30f3ad3c0d9c8c6c2dd792ff3a1f11d301a74d Mon Sep 17 00:00:00 2001
From: jkerdreu <jkerdreu@b32b6428-25c9-4566-ad07-03861ab6144f>
Date: Wed, 12 Jun 2019 14:42:35 +0000
Subject: [PATCH] =?UTF-8?q?Test=20pour=20la=20d=C3=A9mo=20du=2028.?=
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@2210 b32b6428-25c9-4566-ad07-03861ab6144f
---
 scripts/ensibs_btn.py | 114 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)
 create mode 100644 scripts/ensibs_btn.py

diff --git a/scripts/ensibs_btn.py b/scripts/ensibs_btn.py
new file mode 100644
index 00000000..49b74c31
--- /dev/null
+++ b/scripts/ensibs_btn.py
@@ -0,0 +1,114 @@
+from xaal.lib import Engine
+from xaal.schemas import devices
+from xaal.monitor import Monitor
+import platform
+
+PKG_NAME = 'scenario_btn_ensibs'
+
+LAMPS=['aa8cd2e4-8c5d-11e9-b0ba-b827ebe99201']
+
+# Edisio labo
+EDISIO=['43c06446-8c5c-11e9-a105-b80673742b01','43c06446-8c5c-11e9-a105-b80673742b03','43c06446-8c5c-11e9-a105-b80673742b05',
+        '43c06446-8c5c-11e9-a105-b80673742b07','43c06446-8c5c-11e9-a105-b80673742b08']
+
+# Aquara sw1
+AQUARA_1=['fb1f8648-20ba-11e9-b352-a4badbf92500','fb1f8648-20ba-11e9-b352-a4badbf92501','fb1f8648-20ba-11e9-b352-a4badbf92502']
+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']
+
+SIREN = ['980a639c-20b1-11e9-8d70-a4badbf92501',]
+PUSH_BULLET=['bc5bb184-8d16-11e9-b4db-9cebe88e1963']
+
+LAMPS_A = [LAMPS[0]]
+
+BLINKS = ['aa8cd2e4-8c5d-11e9-b0ba-b827ebe99201','980a639c-20b1-11e9-8d70-a4badbf92500']
+
+RELAYS = ['d34fd5be-8c58-11e9-8999-b827ebe99201']
+
+mon = None
+dev = None
+
+def send(targets,action,body=None):
+    global mon,dev
+    engine = mon.dev.engine
+    engine.send_request(dev,targets,action,body)
+
+def search_for_light(lamps):
+    for l in lamps:
+        dev = mon.devices.get_with_addr(l)
+        if dev:
+            light = dev.attributes.get('light',None)
+            if light:
+                return True
+    return False
+
+def on_off_light(lamps):
+    print('on_off %s' % lamps)
+    if search_for_light(lamps):
+        send(lamps,'off')
+        return False
+    else:
+        send(lamps,'on')
+        return True
+
+def siren_play(snd=2):
+    send(SIREN,'play',{'sound':snd})
+
+def siren_stop():
+    send(SIREN,'stop')
+
+def pushbullet(title,msg):
+    send(PUSH_BULLET,'notify',{'title': title,'msg':msg})
+
+def blink():
+    send(BLINKS,'blink')
+
+
+def handle_msg(msg):
+    if not msg.is_notify():
+        return
+    # search for the buttons 
+    if msg.action == 'click':
+        if msg.source == AQUARA_R:
+            blink()
+            siren_play(2)
+            pushbullet('Alerte','')
+
+        if msg.source == AQUARA_1[0]:
+            #on_off_light(LAMPS_A)
+            send(RELAYS,'on')
+
+        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)
+
+        if msg.source == AQUARA_2[2]:
+            siren_stop()
+
+            #send(SHUTERS,'stop')
+
+                
+def main():
+    global mon,dev
+    dev = devices.basic()
+    dev.info = '%s@%s' % (PKG_NAME,platform.node())
+    engine = Engine()
+    engine.add_device(dev)
+    engine.add_rx_handler(handle_msg)
+    mon = Monitor(dev)
+    engine.run()
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        print('Bye bye')
-- 
GitLab