Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
0eb6792d
Commit
0eb6792d
authored
3 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Format & cleanup
parent
9cd2a79e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/btn_relay_labo.py
+132
-83
132 additions, 83 deletions
scripts/btn_relay_labo.py
with
132 additions
and
83 deletions
scripts/btn_relay_labo.py
+
132
−
83
View file @
0eb6792d
from
xaal.lib
import
Engine
,
tools
from
xaal.lib
import
Engine
,
tools
from
xaal.schemas
import
devices
from
xaal.monitor
import
Monitor
import
platform
,
time
import
platform
PKG_NAME
=
'
btn_relay_labo
'
PKG_NAME
=
"
btn_relay_labo
"
def
UUID
(
uuids
):
...
...
@@ -13,37 +13,80 @@ def UUID(uuids):
return
r
LAMPS
=
UUID
([
'
ccc44227-d4fc-46eb-8578-159e2c47da03
'
,
'
ccc44227-d4fc-46eb-8578-159e2c47da04
'
,
'
ccc44227-d4fc-46eb-8578-159e2c47da05
'
,
'
ccc44227-d4fc-46eb-8578-159e2c47da06
'
,
'
ccc44227-d4fc-46eb-8578-159e2c47da07
'
,
'
ccc44227-d4fc-46eb-8578-159e2c47da08
'
])
LAMPS
=
UUID
(
[
"
ccc44227-d4fc-46eb-8578-159e2c47da03
"
,
"
ccc44227-d4fc-46eb-8578-159e2c47da04
"
,
"
ccc44227-d4fc-46eb-8578-159e2c47da05
"
,
"
ccc44227-d4fc-46eb-8578-159e2c47da06
"
,
"
ccc44227-d4fc-46eb-8578-159e2c47da07
"
,
"
ccc44227-d4fc-46eb-8578-159e2c47da08
"
,
]
)
SPOTS
=
UUID
([
'
6265eb30-8c59-11e9-98b1-b827ebe99201
'
,
])
AMBI
=
UUID
([
'
e19d5ea8-c838-11ea-82a8-9cebe88e1963
'
])
SPOTS
=
UUID
([
"
6265eb30-8c59-11e9-98b1-b827ebe99201
"
])
AMBI
=
UUID
([
"
e19d5ea8-c838-11ea-82a8-9cebe88e1963
"
])
# Edisio labo
BTNS
=
UUID
([
'
743034ca-c2f0-11e8-9485-a40074bcb601
'
,
'
743034ca-c2f0-11e8-9485-a40074bcb603
'
,
'
743034ca-c2f0-11e8-9485-a40074bcb605
'
,
'
743034ca-c2f0-11e8-9485-a40074bcb607
'
,
'
743034ca-c2f0-11e8-9485-a40074bcb608
'
])
BTNS
=
UUID
(
[
"
743034ca-c2f0-11e8-9485-a40074bcb601
"
,
"
743034ca-c2f0-11e8-9485-a40074bcb603
"
,
"
743034ca-c2f0-11e8-9485-a40074bcb605
"
,
"
743034ca-c2f0-11e8-9485-a40074bcb607
"
,
"
743034ca-c2f0-11e8-9485-a40074bcb608
"
,
]
)
# Aquara sw1
AQUARA
=
UUID
([
'
1ec6bbd0-20b5-11e9-b352-a4badbf92500
'
])
SDB
=
UUID
([
'
fb1f8648-20ba-11e9-b352-a4badbf92500
'
,
'
fb1f8648-20ba-11e9-b352-a4badbf92501
'
,
'
fb1f8648-20ba-11e9-b352-a4badbf92502
'
])
SCEN
=
UUID
([
'
00796898-20bb-11e9-b352-a4badbf92500
'
,
'
00796898-20bb-11e9-b352-a4badbf92501
'
,
'
00796898-20bb-11e9-b352-a4badbf92502
'
])
BTN_LUM
=
UUID
([
'
ee220704-e54d-11eb-9dbb-a4badbf92500
'
,
'
ee249546-e54d-11eb-9dbb-a4badbf92500
'
,
'
ee25b43a-e54d-11eb-9dbb-a4badbf92500
'
,
'
ee25238a-e54d-11eb-9dbb-a4badbf92500
'
,
'
ee22bfaa-e54d-11eb-9dbb-a4badbf92500
'
])
BTN_SHUT
=
UUID
([
'
ee23caee-e54d-11eb-9dbb-a4badbf92500
'
,
'
ee23caee-e54d-11eb-9dbb-a4badbf92501
'
,
'
ee23caee-e54d-11eb-9dbb-a4badbf92502
'
])
BTN_SCREEN
=
UUID
([
'
ee22bfaa-e54d-11eb-9dbb-a4badbf92501
'
,])
SCREEN_POWER
=
UUID
([
'
2d42a742-aa2f-11e9-ac3b-a4badbf92501
'
,])
AQUARA
=
UUID
([
"
1ec6bbd0-20b5-11e9-b352-a4badbf92500
"
])
SDB
=
UUID
(
[
"
fb1f8648-20ba-11e9-b352-a4badbf92500
"
,
"
fb1f8648-20ba-11e9-b352-a4badbf92501
"
,
"
fb1f8648-20ba-11e9-b352-a4badbf92502
"
,
]
)
SCEN
=
UUID
(
[
"
00796898-20bb-11e9-b352-a4badbf92500
"
,
"
00796898-20bb-11e9-b352-a4badbf92501
"
,
"
00796898-20bb-11e9-b352-a4badbf92502
"
,
]
)
BTN_LUM
=
UUID
(
[
"
ee220704-e54d-11eb-9dbb-a4badbf92500
"
,
"
ee249546-e54d-11eb-9dbb-a4badbf92500
"
,
"
ee25b43a-e54d-11eb-9dbb-a4badbf92500
"
,
"
ee25238a-e54d-11eb-9dbb-a4badbf92500
"
,
"
ee22bfaa-e54d-11eb-9dbb-a4badbf92500
"
,
]
)
BTN_SHUT
=
UUID
(
[
"
ee23caee-e54d-11eb-9dbb-a4badbf92500
"
,
"
ee23caee-e54d-11eb-9dbb-a4badbf92501
"
,
"
ee23caee-e54d-11eb-9dbb-a4badbf92502
"
,
]
)
BTN_SCREEN
=
UUID
([
"
ee22bfaa-e54d-11eb-9dbb-a4badbf92501
"
])
SCREEN_POWER
=
UUID
([
"
2d42a742-aa2f-11e9-ac3b-a4badbf92501
"
])
# Edisio bureau
#BTNS = ['c4b33536-c314-11e8-a5d6-000673742b01','c4b33536-c314-11e8-a5d6-000673742b03','c4b33536-c314-11e8-a5d6-000673742b05',
#
BTNS = ['c4b33536-c314-11e8-a5d6-000673742b01','c4b33536-c314-11e8-a5d6-000673742b03','c4b33536-c314-11e8-a5d6-000673742b05',
# 'c4b33536-c314-11e8-a5d6-000673742b07','c4b33536-c314-11e8-a5d6-000673742b08']
SHUTERS
=
UUID
([
'
e4b05165-be5d-46d5-acd0-4da7be1158ed
'
,
'
2fe70f46-3ece-44d1-af34-2d82e10fb854
'
])
SIRENS
=
UUID
([
'
980a639c-20b1-11e9-8d70-a4badbf92501
'
,])
SHUTERS
=
UUID
(
[
"
e4b05165-be5d-46d5-acd0-4da7be1158ed
"
,
"
2fe70f46-3ece-44d1-af34-2d82e10fb854
"
]
)
SIRENS
=
UUID
([
"
980a639c-20b1-11e9-8d70-a4badbf92501
"
])
LAMPS_A
=
[
LAMPS
[
0
],
LAMPS
[
2
],
LAMPS
[
5
]]
LAMPS_B
=
[
LAMPS
[
1
],
LAMPS
[
3
],
LAMPS
[
4
]]
...
...
@@ -51,34 +94,37 @@ LAMPS_B = [LAMPS[1], LAMPS[3], LAMPS[4]]
mon
=
None
def
send
(
targets
,
action
,
body
=
None
):
def
send
(
targets
,
action
,
body
=
None
):
global
mon
engine
=
mon
.
dev
.
engine
print
(
f
"
{
targets
}
{
action
}
"
)
engine
.
send_request
(
dev
,
targets
,
action
,
body
)
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
)
light
=
dev
.
attributes
.
get
(
"
light
"
,
None
)
if
light
:
return
True
return
False
def
on_off_light
(
lamps
):
if
search_for_light
(
lamps
):
send
(
lamps
,
'
turn_off
'
)
send
(
lamps
,
"
turn_off
"
)
return
False
else
:
send
(
lamps
,
'
turn_on
'
)
send
(
lamps
,
"
turn_on
"
)
return
True
def
handle_msg
(
msg
):
if
not
msg
.
is_notify
():
return
# search for the buttons
if
msg
.
action
==
'
click
'
:
# search for the buttons
if
msg
.
action
==
"
click
"
:
if
msg
.
source
==
BTNS
[
0
]:
on_off_light
(
LAMPS_A
)
...
...
@@ -90,51 +136,54 @@ def handle_msg(msg):
ALL
=
LAMPS
+
SPOTS
+
AMBI
r
=
search_for_light
(
ALL
)
if
r
:
send
(
ALL
,
'
turn_off
'
)
send
(
ALL
,
"
turn_off
"
)
else
:
send
(
LAMPS
,
'
turn_on
'
)
send
(
LAMPS
,
"
turn_on
"
)
# Eclairage d'ambiance
if
msg
.
source
==
BTNS
[
3
]:
on_off_light
(
SPOTS
+
AMBI
)
on_off_light
(
SPOTS
+
AMBI
)
if
msg
.
source
in
AQUARA
:
if
on_off_light
(
LAMPS
):
#send([SHUTERS[0],],'up')
#send([SHUTERS[1],],'up')
#
send([SHUTERS[0],],'up')
#
send([SHUTERS[1],],'up')
pass
else
:
#send([SHUTERS[0],],'down')
#send([SHUTERS[1],],'down')
#
send([SHUTERS[0],],'down')
#
send([SHUTERS[1],],'down')
pass
if
msg
.
source
==
SDB
[
0
]:
send
([
LAMPS
[
3
]
,
],
'
toggle
'
)
send
([
LAMPS
[
3
]],
"
toggle
"
)
if
msg
.
source
==
SCEN
[
0
]:
# "soirée TV"
send
(
SCREEN_POWER
,
'
turn_on
'
)
send
([
SHUTERS
[
0
]],
'
down
'
)
send
(
LAMPS
,
'
turn_off
'
)
send
(
SPOTS
+
AMBI
,
'
turn_on
'
)
send
([
SHUTERS
[
1
]],
'
down
'
)
send
(
SCREEN_POWER
,
"
turn_on
"
)
send
([
SHUTERS
[
0
]],
"
down
"
)
send
(
LAMPS
,
"
turn_off
"
)
send
(
SPOTS
+
AMBI
,
"
turn_on
"
)
send
([
SHUTERS
[
1
]],
"
down
"
)
if
msg
.
source
==
SCEN
[
1
]:
# "Début journée"
send
([
SHUTERS
[
0
]],
'
up
'
)
send
([
LAMPS
[
3
],],
'
turn_on
'
)
send
(
SPOTS
+
AMBI
,
'
turn_off
'
)
send
([
SHUTERS
[
1
]],
'
up
'
)
send
([
SHUTERS
[
0
]],
"
up
"
)
send
(
[
LAMPS
[
3
],
],
"
turn_on
"
,
)
send
(
SPOTS
+
AMBI
,
"
turn_off
"
)
send
([
SHUTERS
[
1
]],
"
up
"
)
if
msg
.
source
==
SCEN
[
2
]:
# "stop"
send
([
SHUTERS
[
0
]],
'
stop
'
)
send
([
SHUTERS
[
1
]],
'
stop
'
)
send
(
SIRENS
,
'
stop
'
)
send
([
SHUTERS
[
0
]],
"
stop
"
)
send
([
SHUTERS
[
1
]],
"
stop
"
)
send
(
SIRENS
,
"
stop
"
)
# ========= Commande éclairage séparé =====
# ========= Commande éclairage séparé =====
if
msg
.
source
==
BTN_LUM
[
0
]:
on_off_light
([
LAMPS
[
0
]])
...
...
@@ -150,59 +199,59 @@ def handle_msg(msg):
if
msg
.
source
==
BTN_LUM
[
4
]:
on_off_light
([
LAMPS
[
5
]])
# ======== Commandes des volets =========
if
msg
.
source
==
BTN_SHUT
[
0
]:
send
(
SHUTERS
,
'
up
'
)
send
(
SHUTERS
,
"
up
"
)
if
msg
.
source
==
BTN_SHUT
[
1
]:
send
(
SHUTERS
,
'
down
'
)
send
(
SHUTERS
,
"
down
"
)
if
msg
.
source
==
BTN_SHUT
[
2
]:
send
(
SHUTERS
,
'
stop
'
)
send
(
SHUTERS
,
"
stop
"
)
# ======= TV
if
msg
.
source
in
BTN_SCREEN
:
tv
=
mon
.
devices
.
get_with_addr
(
SCREEN_POWER
[
0
])
if
tv
:
state
=
tv
.
attributes
.
get
(
'
power
'
,
None
)
if
state
==
True
:
send
(
SCREEN_POWER
,
'
turn_off
'
)
state
=
tv
.
attributes
.
get
(
"
power
"
,
None
)
if
state
==
True
:
send
(
SCREEN_POWER
,
"
turn_off
"
)
elif
state
==
False
:
send
(
SCREEN_POWER
,
'
turn_on
'
)
send
(
SCREEN_POWER
,
"
turn_on
"
)
else
:
print
(
'
Unkown state for main screen
'
)
print
(
"
Unkown state for main screen
"
)
if
msg
.
action
==
'
double_click
'
:
if
msg
.
action
==
"
double_click
"
:
if
msg
.
source
in
AQUARA
:
send
([
SHUTERS
[
0
],],
'
stop
'
)
send
([
SHUTERS
[
1
],],
'
stop
'
)
send
(
SIRENS
,
'
stop
'
)
if
msg
.
action
==
'
attributesChange
'
:
#print(msg)
if
msg
.
source
==
tools
.
get_uuid
(
'
d9993018-20b1-11e9-a250-a4badbf92500
'
):
pres
=
msg
.
body
.
get
(
'
presence
'
)
light
=
mon
.
devices
.
get_with_addr
(
LAMPS
[
3
]).
attributes
.
get
(
'
light
'
)
print
(
"
pres & light %s/%s
"
%
(
pres
,
light
))
if
pres
==
False
and
light
==
True
:
send
(
SIRENS
,
'
play
'
)
print
(
'
Alarme..
'
)
send
([
SHUTERS
[
0
]],
"
stop
"
)
send
([
SHUTERS
[
1
]],
"
stop
"
)
send
(
SIRENS
,
"
stop
"
)
if
msg
.
action
==
"
attributesChange
"
:
# print(msg)
if
msg
.
source
==
tools
.
get_uuid
(
"
d9993018-20b1-11e9-a250-a4badbf92500
"
):
pres
=
msg
.
body
.
get
(
"
presence
"
)
light
=
mon
.
devices
.
get_with_addr
(
LAMPS
[
3
]).
attributes
.
get
(
"
light
"
)
print
(
"
pres & light %s/%s
"
%
(
pres
,
light
))
if
not
pres
and
light
:
send
(
SIRENS
,
"
play
"
)
print
(
"
Alarme..
"
)
def
main
():
global
dev
global
mon
dev
=
devices
.
basic
()
dev
.
info
=
'
%s@%s
'
%
(
PKG_NAME
,
platform
.
node
())
dev
.
info
=
"
%s@%s
"
%
(
PKG_NAME
,
platform
.
node
())
engine
=
Engine
()
engine
.
add_device
(
dev
)
engine
.
subscribe
(
handle_msg
)
mon
=
Monitor
(
dev
)
engine
.
run
()
if
__name__
==
'
__main__
'
:
if
__name__
==
"
__main__
"
:
try
:
eng
=
main
()
except
KeyboardInterrupt
:
print
(
'
Bye bye
'
)
print
(
"
Bye bye
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment