|
@@ -1,6 +1,13 @@
|
1
|
1
|
"""Python bindings for PD Buddy Sink configuration"""
|
2
|
2
|
|
3
|
|
-from enum import *
|
|
3
|
+try:
|
|
4
|
+ # Try importing enum from the standard library
|
|
5
|
+ import enum
|
|
6
|
+ # Make sure Flag is available
|
|
7
|
+ enum.Flag
|
|
8
|
+except (ImportError, NameError):
|
|
9
|
+ # If something above failed, try aenum instead
|
|
10
|
+ import aenum as enum
|
4
|
11
|
|
5
|
12
|
import serial
|
6
|
13
|
import serial.tools.list_ports
|
|
@@ -38,7 +45,7 @@ class Sink:
|
38
|
45
|
printed as a response to the command.
|
39
|
46
|
"""
|
40
|
47
|
# Send the command
|
41
|
|
- self._port.write(bytes(cmd, "utf-8") + b"\r\n")
|
|
48
|
+ self._port.write(cmd.encode("utf-8") + b"\r\n")
|
42
|
49
|
self._port.flush()
|
43
|
50
|
|
44
|
51
|
# Read the result
|
|
@@ -167,7 +174,7 @@ class SinkConfig:
|
167
|
174
|
self.i = i
|
168
|
175
|
|
169
|
176
|
def __repr__(self):
|
170
|
|
- s = type(self).__name__ + "("
|
|
177
|
+ s = self.__class__.__name__ + "("
|
171
|
178
|
|
172
|
179
|
if self.status is not None:
|
173
|
180
|
s += "status={}".format(self.status)
|
|
@@ -301,14 +308,14 @@ class SinkConfig:
|
301
|
308
|
return cls(status=status, flags=flags, v=v, i=i)
|
302
|
309
|
|
303
|
310
|
|
304
|
|
-class SinkStatus(Enum):
|
|
311
|
+class SinkStatus(enum.Enum):
|
305
|
312
|
"""Status field of a PD Buddy Sink configuration object"""
|
306
|
313
|
EMPTY = 1
|
307
|
314
|
VALID = 2
|
308
|
315
|
INVALID = 3
|
309
|
316
|
|
310
|
317
|
|
311
|
|
-class SinkFlags(Flag):
|
|
318
|
+class SinkFlags(enum.Flag):
|
312
|
319
|
"""Flags field of a PD Buddy Sink configuration object"""
|
313
|
320
|
NONE = 0
|
314
|
|
- GIVEBACK = auto()
|
|
321
|
+ GIVEBACK = enum.auto()
|