forked from OpenZWave/python-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lib.py
More file actions
executable file
·85 lines (73 loc) · 3 KB
/
test_lib.py
File metadata and controls
executable file
·85 lines (73 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.
:platform: Unix, Windows, MacOS X
:sinopsis: openzwave wrapper
.. moduleauthor:: bibi21000 aka Sébastien GALLET <bibi21000@gmail.com>
License : GPL(v3)
**python-openzwave** is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
**python-openzwave** is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with python-openzwave. If not, see http://www.gnu.org/licenses.
"""
import sys, os
import time
import libopenzwave
from libopenzwave import PyManager
device="/dev/ttyUSB0"
log="Info"
sniff=60.0
for arg in sys.argv:
if arg.startswith("--device"):
temp,device = arg.split("=")
elif arg.startswith("--log"):
temp,log = arg.split("=")
elif arg.startswith("--sniff"):
temp,sniff = arg.split("=")
sniff = float(sniff)
if arg.startswith("--help"):
print("help : ")
print(" --device=/dev/yourdevice ")
print(" --log=Info|Debug")
print(" --sniff=0 : sniff for zwave messages a number of seconds")
exit(0)
options = libopenzwave.PyOptions(config_path="../openzwave/config", \
user_path=".", cmd_line="--logging true")
# Specify the open-zwave config path here
options.lock()
manager = libopenzwave.PyManager()
manager.create()
# callback order: (notificationtype, homeid, nodeid, ValueID, groupidx, event)
def callback(args):
print('\n-------------------------------------------------')
print('\n[{}]:\n'.format(args['notificationType']))
if args:
print('homeId: 0x{0:08x}'.format(args['homeId']))
print('nodeId: {}'.format(args['nodeId']))
if 'valueId' in args:
v = args['valueId']
print('valueID: {}'.format(v['id']))
if 'groupIndex' in v and v['groupIndex'] != 0xff: print('GroupIndex: {}'.format(v['groupIndex']))
if 'event' in v and v['event'] != 0xff: print('Event: {}'.format(v['event']))
if 'value' in v: print('Value: {}'.format(str(v['value'])))
if 'label' in v: print('Label: {}'.format(v['label']))
if 'units' in v: print('Units: {}'.format(v['units']))
if 'readOnly' in v: print('ReadOnly: {}'.format(v['readOnly']))
print('-------------------------------------------------\n')
print("Add watcher")
manager.addWatcher(callback)
print("Add device")
manager.addDriver(device)
print("Sniff network during {} seconds".format(sniff))
time.sleep(sniff)
print("Remove watcher")
manager.removeWatcher(callback)
print("Remove device")
manager.removeDriver(device)