Skip to content

Commit 05399dc

Browse files
committed
Ran black, updated to pylint 2.x
1 parent 7e56b88 commit 05399dc

15 files changed

+156
-121
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_bluefruit_connect/_xyz_packet.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333

3434
from .packet import Packet
3535

36+
3637
class _XYZPacket(Packet):
3738
"""A packet of x, y, z float values. Used for several different Bluefruit controller packets."""
3839

39-
_FMT_PARSE = '<xxfffx'
40+
_FMT_PARSE = "<xxfffx"
4041
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
4142
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
42-
_FMT_CONSTRUCT = '<2sfff'
43+
_FMT_CONSTRUCT = "<2sfff"
4344
# _TYPE_HEADER is set by each concrete subclass.
4445

4546
def __init__(self, x, y, z):
@@ -53,8 +54,9 @@ def __init__(self, x, y, z):
5354
def to_bytes(self):
5455
"""Return the bytes needed to send this packet.
5556
"""
56-
partial_packet = struct.pack(self._FMT_CONSTRUCT, self._TYPE_HEADER,
57-
self._x, self._y, self._z)
57+
partial_packet = struct.pack(
58+
self._FMT_CONSTRUCT, self._TYPE_HEADER, self._x, self._y, self._z
59+
)
5860
return self.add_checksum(partial_packet)
5961

6062
@property

adafruit_bluefruit_connect/accelerometer_packet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131

3232
from ._xyz_packet import _XYZPacket
3333

34+
3435
class AccelerometerPacket(_XYZPacket):
3536
"""A packet of x, y, z float values from an accelerometer."""
3637

3738
# Everything else is handled by _XYZPacket.
38-
_TYPE_HEADER = b'!A'
39+
_TYPE_HEADER = b"!A"
3940

4041

4142
# Register this class with the superclass. This allows the user to import only what is needed.

adafruit_bluefruit_connect/button_packet.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,33 @@
3434

3535
from .packet import Packet
3636

37+
3738
class ButtonPacket(Packet):
3839
"""A packet containing a button name and its state."""
3940

40-
BUTTON_1 = '1'
41+
BUTTON_1 = "1"
4142
"""Code for Button 1 on the Bluefruit LE Connect app Control Pad screen."""
42-
BUTTON_2 = '2'
43+
BUTTON_2 = "2"
4344
"""Button 2."""
44-
BUTTON_3 = '3'
45+
BUTTON_3 = "3"
4546
"""Button 3."""
46-
BUTTON_4 = '4'
47+
BUTTON_4 = "4"
4748
"""Button 4."""
48-
#pylint: disable= invalid-name
49-
UP = '5'
49+
# pylint: disable= invalid-name
50+
UP = "5"
5051
"""Up Button."""
51-
DOWN = '6'
52+
DOWN = "6"
5253
"""Down Button."""
53-
LEFT = '7'
54+
LEFT = "7"
5455
"""Left Button."""
55-
RIGHT = '8'
56+
RIGHT = "8"
5657
"""Right Button."""
5758

58-
_FMT_PARSE = '<xxssx'
59+
_FMT_PARSE = "<xxssx"
5960
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
6061
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
61-
_FMT_CONSTRUCT = '<2sss'
62-
_TYPE_HEADER = b'!B'
62+
_FMT_CONSTRUCT = "<2sss"
63+
_TYPE_HEADER = b"!B"
6364

6465
def __init__(self, button, pressed):
6566
"""Construct a ButtonPacket from a button name and the button's state.
@@ -83,14 +84,18 @@ def parse_private(cls, packet):
8384
pylint makes it difficult to call this method _parse(), hence the name.
8485
"""
8586
button, pressed = struct.unpack(cls._FMT_PARSE, packet)
86-
if not pressed in b'01':
87+
if not pressed in b"01":
8788
raise ValueError("Bad button press/release value")
88-
return cls(chr(button[0]), pressed == b'1')
89+
return cls(chr(button[0]), pressed == b"1")
8990

9091
def to_bytes(self):
9192
"""Return the bytes needed to send this packet."""
92-
partial_packet = struct.pack(self._FMT_CONSTRUCT, self._TYPE_HEADER,
93-
self._button, b'1' if self._pressed else b'0')
93+
partial_packet = struct.pack(
94+
self._FMT_CONSTRUCT,
95+
self._TYPE_HEADER,
96+
self._button,
97+
b"1" if self._pressed else b"0",
98+
)
9499
return self.add_checksum(partial_packet)
95100

96101
@property

adafruit_bluefruit_connect/color_packet.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333

3434
from .packet import Packet
3535

36+
3637
class ColorPacket(Packet):
3738
"""A packet containing an RGB color value."""
3839

39-
_FMT_PARSE = '<xx3Bx'
40+
_FMT_PARSE = "<xx3Bx"
4041
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
4142
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
42-
_FMT_CONSTRUCT = '<2s3B'
43-
_TYPE_HEADER = b'!C'
43+
_FMT_CONSTRUCT = "<2s3B"
44+
_TYPE_HEADER = b"!C"
4445

4546
def __init__(self, color):
4647
"""Construct a ColorPacket from a 3-tuple of RGB values,
@@ -50,7 +51,7 @@ def __init__(self, color):
5051
or an int color value ``0xRRGGBB``
5152
"""
5253
if isinstance(color, int):
53-
self._color = tuple(color.to_bytes('BBB', 'big'))
54+
self._color = tuple(color.to_bytes("BBB", "big"))
5455
elif len(color) == 3 and all(0 <= c <= 255 for c in color):
5556
self._color = color
5657
else:
@@ -67,7 +68,9 @@ def parse_private(cls, packet):
6768
def to_bytes(self):
6869
"""Return the bytes needed to send this packet.
6970
"""
70-
partial_packet = struct.pack(self._FMT_CONSTRUCT, self._TYPE_HEADER, *self._color)
71+
partial_packet = struct.pack(
72+
self._FMT_CONSTRUCT, self._TYPE_HEADER, *self._color
73+
)
7174
return self.add_checksum(partial_packet)
7275

7376
@property

adafruit_bluefruit_connect/gyro_packet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131

3232
from ._xyz_packet import _XYZPacket
3333

34+
3435
class GyroPacket(_XYZPacket):
3536
"""A packet of x, y, z float values from a gyroscope."""
3637

3738
# Everything else is handled by _XYZPacket.
38-
_TYPE_HEADER = b'!G'
39+
_TYPE_HEADER = b"!G"
3940

4041

4142
# Register this class with the superclass. This allows the user to import only what is needed.

adafruit_bluefruit_connect/location_packet.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@
3333

3434
from .packet import Packet
3535

36+
3637
class LocationPacket(Packet):
3738
"""A packet of latitude, longitude, and altitude values."""
3839

39-
_FMT_PARSE = '<xxfffx'
40+
_FMT_PARSE = "<xxfffx"
4041
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
4142
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
42-
_FMT_CONSTRUCT = '<2sfff'
43-
_TYPE_HEADER = b'!L'
43+
_FMT_CONSTRUCT = "<2sfff"
44+
_TYPE_HEADER = b"!L"
4445

4546
def __init__(self, latitude, longitude, altitude):
4647
"""Construct a LocationPacket from the given values."""
@@ -51,8 +52,13 @@ def __init__(self, latitude, longitude, altitude):
5152
def to_bytes(self):
5253
"""Return the bytes needed to send this packet.
5354
"""
54-
partial_packet = struct.pack(self._FMT_CONSTRUCT, self._TYPE_HEADER,
55-
self._latitude, self._longitude, self._altitude)
55+
partial_packet = struct.pack(
56+
self._FMT_CONSTRUCT,
57+
self._TYPE_HEADER,
58+
self._latitude,
59+
self._longitude,
60+
self._altitude,
61+
)
5662
return self.add_checksum(partial_packet)
5763

5864
@property
@@ -70,5 +76,6 @@ def altitude(self):
7076
"""The altitude value."""
7177
return self._altitude
7278

79+
7380
# Register this class with the superclass. This allows the user to import only what is needed.
7481
LocationPacket.register_packet_type()

adafruit_bluefruit_connect/magnetometer_packet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131

3232
from ._xyz_packet import _XYZPacket
3333

34+
3435
class MagnetometerPacket(_XYZPacket):
3536
"""A packet of x, y, z float values from a magnetometer."""
3637

3738
# Everything else is handled by _XYZPacket.
38-
_TYPE_HEADER = b'!M'
39+
_TYPE_HEADER = b"!M"
3940

4041

4142
# Register this class with the superclass. This allows the user to import only what is needed.

adafruit_bluefruit_connect/packet.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import struct
3333

34+
3435
class Packet:
3536
"""
3637
A Bluefruit app controller packet. A packet consists of these bytes, in order:
@@ -80,7 +81,7 @@ def from_bytes(cls, packet):
8081
# In case this was called from a subclass, make sure the parsed
8182
# type matches up with the current class.
8283
if not issubclass(packet_class, cls):
83-
raise ValueError('Packet type is not a {}'.format(cls.__name__))
84+
raise ValueError("Packet type is not a {}".format(cls.__name__))
8485

8586
if len(packet) != packet_class.PACKET_LENGTH:
8687
raise ValueError("Wrong length packet")
@@ -110,14 +111,13 @@ def from_stream(cls, stream):
110111
if not start:
111112
# Timeout: nothing read.
112113
return None
113-
if start == b'!':
114+
if start == b"!":
114115
# Found start of packet.
115116
packet_type = stream.read(1)
116117
if not packet_type:
117118
# Timeout: nothing more read.
118119
return None
119-
else:
120-
break
120+
break
121121
# Didn't find a packet start. Loop and try again.
122122

123123
header = start + packet_type
@@ -142,7 +142,7 @@ def parse_private(cls, packet):
142142
@staticmethod
143143
def checksum(partial_packet):
144144
"""Compute checksum for bytes, not including the checksum byte itself."""
145-
return ~sum(partial_packet) & 0xff
145+
return ~sum(partial_packet) & 0xFF
146146

147147
def add_checksum(self, partial_packet):
148148
"""Compute the checksum of partial_packet and return a new bytes

adafruit_bluefruit_connect/quaternion_packet.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@
3333

3434
from ._xyz_packet import _XYZPacket
3535

36+
3637
class QuaternionPacket(_XYZPacket):
3738
"""A packet of x, y, z float values. Used for several different Bluefruit controller packets."""
3839

3940
# Use _XYZPacket to handle x, y, z, and add w.
4041

41-
_FMT_PARSE = '<xxffffx'
42+
_FMT_PARSE = "<xxffffx"
4243
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
4344
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
44-
_FMT_CONSTRUCT = '<2sffff'
45-
_TYPE_HEADER = b'!Q'
45+
_FMT_CONSTRUCT = "<2sffff"
46+
_TYPE_HEADER = b"!Q"
4647

4748
def __init__(self, x, y, z, w):
4849
"""Construct a QuaternionPacket from the given x, y, z, and w float values."""
@@ -52,14 +53,16 @@ def __init__(self, x, y, z, w):
5253
def to_bytes(self):
5354
"""Return the bytes needed to send this packet.
5455
"""
55-
partial_packet = struct.pack(self._FMT_CONSTRUCT, self._TYPE_HEADER,
56-
self._x, self._y, self._z, self._w)
56+
partial_packet = struct.pack(
57+
self._FMT_CONSTRUCT, self._TYPE_HEADER, self._x, self._y, self._z, self._w
58+
)
5759
return partial_packet + self.checksum(partial_packet)
5860

5961
@property
6062
def w(self):
6163
"""The w value."""
6264
return self._w
6365

66+
6467
# Register this class with the superclass. This allows the user to import only what is needed.
6568
QuaternionPacket.register_packet_type()

0 commit comments

Comments
 (0)