-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.py
110 lines (63 loc) · 1.86 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
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
import threading
class Device():
_lock = threading.RLock()
enabled = True
name = None
def get_input_labels(self):
return None
def get_output_labels(self):
return None
def get_name(self):
"""
Get the name of the device.
By default this is None"""
return self.name
def get_full_name(self):
"""
For when stuff wants to use a longer name
than above"""
return self.get_name()
def getName(self):
raise DeprecationWarning
return self.get_name()
def isEnabled(self):
raise DeprecationWarning
return self.enabled
def setEnabled(self, *args):
raise DeprecationWarning
self.set_enabled(*args)
def is_enabled(self):
return self.enabled
def set_enabled(self, enable = True):
if type(enable) == bool:
self.enabled = enable
else:
raise TypeError('enable must be bool')
def getHost(self):
raise DeprecationWarning
return self.host
def getPort(self):
raise DeprecationWarning
return self.port
def get_host(self):
return self.host
def get_port(self):
return self.port
def setHost(self, *args):
raise DeprecationWarning
return self.set_host(*args)
def setPort(self, *args):
raise DeprecationWarning
return self.set_port(*args)
def set_host(self, host):
self.host = host
def set_port(self, port):
self.port = int(port)
def acquire(self, *args, **kwargs):
self._lock.acquire(*args, **kwargs)
def release(self, *args, **kwargs):
self._lock.release(*args, **kwargs)
def __enter__(self):
self.acquire()
def __exit__(self, type_, value, traceback):
self.release()