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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
49f2f7a7
Commit
49f2f7a7
authored
9 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Format
parent
f10cd3d7
Branches
Branches containing commit
No related tags found
1 merge request
!1
First try of type hints
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
devices/protocols/SensFloor/xaal/sensfloor/gw.py
+40
-41
40 additions, 41 deletions
devices/protocols/SensFloor/xaal/sensfloor/gw.py
with
40 additions
and
41 deletions
devices/protocols/SensFloor/xaal/sensfloor/gw.py
+
40
−
41
View file @
49f2f7a7
from
xaal.lib
import
tools
,
Device
,
AsyncEngine
from
xaal.lib
import
tools
from
xaal.schemas
import
devices
import
asyncio
import
socketio
import
atexit
import
logging
...
...
@@ -29,7 +28,7 @@ class GW(object):
cfg
=
tools
.
new_cfg
(
PACKAGE_NAME
)
cfg
[
'
config
'
][
'
url
'
]
=
'
http://floor1.enstb.org:8000/
'
cfg
[
'
devices
'
]
=
{}
logger
.
warn
(
"
Created an empty config file
"
)
logger
.
warn
ing
(
"
Created an empty config file
"
)
cfg
.
write
()
self
.
cfg
=
cfg
...
...
@@ -47,7 +46,6 @@ class GW(object):
dev
=
self
.
add_device
(
k
,
cfg
[
'
type
'
],
tools
.
get_uuid
(
cfg
[
'
addr
'
]))
self
.
engine
.
add_device
(
dev
)
def
add_device
(
self
,
idx
,
al_type
,
addr
=
None
):
if
not
addr
:
addr
=
tools
.
get_random_uuid
()
...
...
@@ -56,7 +54,7 @@ class GW(object):
dev
=
devices
.
falldetector
(
addr
)
if
al_type
==
'
presence
'
:
dev
=
devices
.
motion
(
addr
)
if
dev
==
None
:
if
dev
is
None
:
return
logger
.
debug
(
f
"
New device
{
addr
}
{
idx
}
"
)
dev
.
vendor_id
=
'
Future Shape
'
...
...
@@ -67,21 +65,19 @@ class GW(object):
self
.
engine
.
add_device
(
dev
)
return
dev
def
get_device
(
self
,
idx
,
al_type
):
dev
=
self
.
devices
.
get
(
idx
,
None
)
return
dev
def
on_alarm
(
self
,
data
):
active
=
[]
for
k
in
data
:
# print(k)
idx
=
str
(
k
[
'
index
'
])
al_type
=
k
[
'
type
'
]
state
=
k
[
'
state
'
]
#
state = k['state']
dev
=
self
.
get_device
(
idx
,
al_type
)
if
dev
==
None
:
if
dev
is
None
:
dev
=
self
.
add_device
(
idx
,
al_type
)
self
.
cfg
[
'
devices
'
][
str
(
idx
)]
=
{
'
addr
'
:
dev
.
address
,
'
type
'
:
al_type
}
...
...
@@ -90,11 +86,11 @@ class GW(object):
active
.
append
(
dev
)
# print(active)
for
dev
in
self
.
devices
.
values
():
if
dev
in
active
:
continue
if
dev
in
active
:
continue
if
dev
.
dev_type
==
'
motion.basic
'
:
dev
.
attributes
[
'
presence
'
]
=
False
def
_exit
(
self
):
cfg
=
tools
.
load_cfg
(
PACKAGE_NAME
)
if
cfg
!=
self
.
cfg
:
...
...
@@ -111,7 +107,9 @@ class GW(object):
def
stop
():
import
pdb
;
pdb
.
set_trace
()
import
pdb
pdb
.
set_trace
()
def
setup
(
eng
):
...
...
@@ -119,3 +117,4 @@ def setup(eng):
eng
.
on_stop
(
stop
)
eng
.
new_task
(
gw
.
sio_task
())
return
True
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
sign in
to comment