-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.py
55 lines (45 loc) · 1.43 KB
/
device.py
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
from zk import ZK
from logger import debug, error, fatal
def deviceInit(host, port=4370, timeout=5, password=0, modeUDP=False, noPing=False):
try:
debug('Host', host)
debug('Port', port)
debug('Timeout', timeout)
debug('UDP', modeUDP)
debug('NoPING', noPing)
device = ZK(host, port, timeout, password, modeUDP, noPing)
debug("Status", "Device created")
return device
except Exception as e:
fatal("getDeviceException", e)
return None
def deviceConnect(device):
try:
deviceConnection = device.connect()
debug("Status", "Device connected")
return deviceConnection
except Exception as e:
error("deviceConnectionException", e)
return None
def deviceDisconnect(deviceConnection):
try:
deviceConnection.disconnect()
debug("Status", "Device disconnected")
except Exception as e:
error("deviceDisconnectException", e)
def deviceDisable(deviceConnection):
try:
deviceConnection.disable_device()
debug("Status", "Device disabled")
return True
except Exception as e:
error("deviceDisableException", e)
return False
def deviceEnable(deviceConnection):
try:
deviceConnection.disable_device()
debug("Status", "Device enabled")
return True
except Exception as e:
error("deviceEnableException", e)
return False