forked from abcminiuser/python-elgato-streamdeck
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTransport.py
More file actions
207 lines (167 loc) · 6.46 KB
/
Copy pathTransport.py
File metadata and controls
207 lines (167 loc) · 6.46 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Python Stream Deck Library
# Released under the MIT license
#
# dean [at] fourwalledcubicle [dot] com
# www.fourwalledcubicle.com
#
from abc import ABC, abstractmethod
class TransportError(Exception):
"""
Exception thrown when attempting to access a device using a backend
transport that has failed (for example, if the requested device could not
be accessed).
"""
pass
class Transport(ABC):
"""
Base transport layer, representing an abstract communication back-end which
can be used to discovery attached StreamDeck devices.
"""
class Device(ABC):
"""
Base connection device, representing an abstract connected device which
can be communicated with by an upper layer high level protocol.
"""
@abstractmethod
def open(self):
"""
Opens the device for input/output. This must be called prior to
sending or receiving any reports.
.. seealso:: See :func:`~Transport.Device.close` for the
corresponding close method.
"""
pass
@abstractmethod
def close(self):
"""
Closes the device for input/output.
.. seealso:: See :func:`~~Transport.Device.open` for the
corresponding open method.
"""
pass
@abstractmethod
def is_open(self):
"""
Indicates if the physical device object this instance is attached
to has been opened by the host.
:rtype: bool
:return: `True` if the device is open, `False` otherwise.
"""
pass
@abstractmethod
def connected(self):
"""
Indicates if the physical device object this instance is attached
to is still connected to the host.
:rtype: bool
:return: `True` if the device is still connected, `False` otherwise.
"""
pass
@abstractmethod
def path(self):
"""
Retrieves the logical path of the attached device within the
current system. This can be used to uniquely differentiate one
device from another.
:rtype: str
:return: Logical device path for the attached device.
"""
pass
@abstractmethod
def vendor_id(self):
"""
Retrieves the vendor ID value of the attached device.
:rtype: int
:return: Vendor ID of the attached device.
"""
pass
@abstractmethod
def product_id(self):
"""
Retrieves the product ID value of the attached device.
:rtype: int
:return: Product ID of the attached device.
"""
pass
@abstractmethod
def write_feature(self, payload):
"""
Sends a HID Feature report to the open HID device.
:param enumerable() payload: Enumerate list of bytes to send to the
device, as a feature report. The first
byte of the report should be the Report
ID of the report being sent.
:rtype: int
:return: Number of bytes successfully sent to the device.
"""
pass
@abstractmethod
def read_feature(self, report_id, length):
"""
Reads a HID Feature report from the open HID device.
:param int report_id: Report ID of the report being read.
:param int length: Maximum length of the Feature report to read.
:rtype: list(byte)
:return: List of bytes containing the read Feature report. The
first byte of the report will be the Report ID of the
report that was read.
"""
pass
@abstractmethod
def read_input(self, report_id, length):
"""
Reads a HID Input report from the open HID device.
:param int report_id: Report ID of the report being read.
:param int length: Maximum length of the Input report to read.
:rtype: list(byte)
:return: List of bytes containing the read Feature report. The
first byte of the report will be the Input ID of the
report that was read.
"""
pass
@abstractmethod
def write(self, payload):
"""
Sends a HID Out report to the open HID device.
:param enumerable() payload: Enumerate list of bytes to send to the
device, as an Out report. The first
byte of the report should be the Report
ID of the report being sent.
:rtype: int
:return: Number of bytes successfully sent to the device.
"""
pass
@abstractmethod
def read(self, length):
"""
Performs a blocking read of a HID In report from the open HID device.
:param int length: Maximum length of the In report to read.
:rtype: list(byte)
:return: List of bytes containing the read In report. The first byte
of the report will be the Report ID of the report that was
read.
"""
pass
@staticmethod
@abstractmethod
def probe():
"""
Attempts to determine if the back-end is installed and usable. It is
expected that probe failures throw exceptions detailing their exact
cause of failure.
"""
pass
@abstractmethod
def enumerate(self, vid, pid):
"""
Enumerates all available devices on the system using the current
transport back-end.
:param int vid: USB Vendor ID to filter all devices by, `None` if the
device list should not be filtered by vendor.
:param int pid: USB Product ID to filter all devices by, `None` if the
device list should not be filtered by product.
:rtype: list(Transport.Device)
:return: List of discovered devices that are available through this
transport back-end.
"""
pass