forked from OpenZWave/python-openzwave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyozw_check
More file actions
194 lines (180 loc) · 7.13 KB
/
Copy pathpyozw_check
File metadata and controls
194 lines (180 loc) · 7.13 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!python
# -*- coding: utf-8 -*-
"""
This file is part of **python-openzwave** project https://github.com/OpenZWave/python-openzwave.
:platform: Unix, Windows, MacOS X
.. 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 logging
h = logging.NullHandler()
logger = logging.getLogger(__name__).addHandler(h)
import time
import argparse
network_state = None
home_id = None
args = None
def imports(args):
if args.output == 'txt':
print("-------------------------------------------------------------------------------")
print("Import libs")
print("Try to import libopenzwave")
import libopenzwave
print("Try to import libopenzwave.PyLogLevels")
from libopenzwave import PyLogLevels
print("Try to get options")
options = libopenzwave.PyOptions(user_path=".", cmd_line="--logging false")
options.lock()
time.sleep(0.5)
print("Try to get manager")
manager = libopenzwave.PyManager()
manager.create()
print("Try to get python_openzwave version")
print(manager.getPythonLibraryVersionNumber())
print("Try to get python_openzwave full version")
print(manager.getPythonLibraryVersion())
print("Try to get openzwave version")
print(manager.getOzwLibraryVersion())
print("Try to get default config path")
print(libopenzwave.configPath())
print("Try to destroy manager")
manager.destroy()
print("Try to destroy options")
options.destroy()
time.sleep(0.5)
print("Try to import openzwave (API)")
import openzwave
elif args.output == 'raw':
import libopenzwave
from libopenzwave import PyLogLevels
options = libopenzwave.PyOptions(user_path=".", cmd_line="--logging false")
options.lock()
time.sleep(0.5)
manager = libopenzwave.PyManager()
manager.create()
print("{0}|{1}|{2}|{3}".format(
manager.getOzwLibraryVersion(),
manager.getPythonLibraryVersionNumber(),
manager.getPythonLibraryVersion(),
libopenzwave.configPath()
))
manager.destroy()
options.destroy()
time.sleep(0.5)
import openzwave
def zwcallback(zwargs):
import libopenzwave
global args
if args.output == 'txt':
print('--------------------------------- zwcallback with args=[%s]' % zwargs)
notify_type = zwargs['notificationType']
global network_state
network_state = notify_type
if notify_type == "DriverReady":
global home_id
home_id = zwargs['homeId']
#~ print("Received {0} : {1}".format(notify_type,libopenzwave.PyNotifications[notify_type].doc))
if args.output == 'txt':
print("Received {0}".format(notify_type))
def init_device(args):
global home_id
if args.output == 'txt':
print("-------------------------------------------------------------------------------")
print("Intialize device {0}".format(args.device))
import libopenzwave
print("Try to get options")
options = libopenzwave.PyOptions(user_path=".", cmd_line="--logging true")
options.lock()
time.sleep(1.0)
print("Try to get manager")
manager = libopenzwave.PyManager()
manager.create()
print("Try to get python_openzwave version")
print(manager.getPythonLibraryVersionNumber())
print("Try to get python_openzwave full version")
print(manager.getPythonLibraryVersion())
print("Try to get openzwave version")
print(manager.getOzwLibraryVersion())
print("Try to get default config path")
print(libopenzwave.configPath())
print("Try to add watcher")
manager.addWatcher(zwcallback)
time.sleep(1.0)
manager.addDriver(args.device)
print("Wait for notifications ({0}s)".format(args.timeout))
next_print = args.timeout/10
delta = 0.1
for i in range(0, int(args.timeout/delta)):
time.sleep(delta)
next_print -= delta
if next_print < 0:
next_print = args.timeout/10
print('.')
print("Try to remove driver")
manager.removeDriver(args.device)
time.sleep(3.0)
print("Try to remove watcher")
manager.removeWatcher(zwcallback)
print("Try to destroy manager")
manager.destroy()
time.sleep(0.2)
print("Try to destroy options")
options.destroy()
time.sleep(1.0)
print("Retrieve HomeID")
print("{0:08x}".format(home_id))
elif args.output == 'raw':
import libopenzwave
options = libopenzwave.PyOptions(user_path=".", cmd_line="--logging false")
options.lock()
time.sleep(1.0)
manager = libopenzwave.PyManager()
manager.create()
manager.addWatcher(zwcallback)
time.sleep(1.0)
manager.addDriver(args.device)
next_print = args.timeout/10
delta = 0.1
for i in range(0, int(args.timeout/delta)):
time.sleep(delta)
print("{0}|{1}|{2}|{3}|{4:08x}".format(
manager.getOzwLibraryVersion(),
manager.getPythonLibraryVersionNumber(),
manager.getPythonLibraryVersion(),
libopenzwave.configPath(),
home_id,
))
manager.removeDriver(args.device)
time.sleep(0.5)
manager.removeWatcher(zwcallback)
manager.destroy()
time.sleep(0.2)
options.destroy()
def pyozw_parser():
parser = argparse.ArgumentParser(description='Run python_openzwave basics checks.')
parser.add_argument('-o', '--output', action='store', help='The format (txt, raw, ...)', choices=['txt', 'raw'], default='txt')
parser.add_argument('-d', '--device', action='store', help='The device port', default='/dev/ttyUSB0')
parser.add_argument('-m', '--imports', action='store_true', help='Import all libs', default=True)
parser.add_argument('-i', '--init_device', action='store_true', help='Intialize the device', default=False)
parser.add_argument('-t', '--timeout', action='store',type=int, help='The default timeout for zwave network sniffing', default=10)
return parser
def main():
parser = pyozw_parser()
global args
args = parser.parse_args()
if args.init_device:
init_device(args)
elif args.imports:
imports(args)
if __name__ == '__main__':
main()