Skip to content
Snippets Groups Projects
Commit 2f30f3ad authored by jkerdreu's avatar jkerdreu
Browse files

Test pour la démo du 28.


git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2210 b32b6428-25c9-4566-ad07-03861ab6144f
parent 705b6d12
Branches
No related tags found
No related merge requests found
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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment