Skip to content

Commit 2052fa3

Browse files
authored
Merge pull request #5 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents f05e60f + 72b56e6 commit 2052fa3

File tree

5 files changed

+133
-101
lines changed

5 files changed

+133
-101
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
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_ble_apple_media.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,49 +45,62 @@
4545
# Disable protected access checks since our private classes are tightly coupled.
4646
# pylint: disable=protected-access
4747

48+
4849
class _RemoteCommand(ComplexCharacteristic):
4950
"""Endpoint for sending commands to a media player. The value read will list all available
5051
5152
commands."""
53+
5254
uuid = VendorUUID("9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2")
5355

5456
def __init__(self):
55-
super().__init__(properties=Characteristic.WRITE_NO_RESPONSE | Characteristic.NOTIFY,
56-
read_perm=Attribute.OPEN, write_perm=Attribute.OPEN,
57-
max_length=13,
58-
fixed_length=False)
57+
super().__init__(
58+
properties=Characteristic.WRITE_NO_RESPONSE | Characteristic.NOTIFY,
59+
read_perm=Attribute.OPEN,
60+
write_perm=Attribute.OPEN,
61+
max_length=13,
62+
fixed_length=False,
63+
)
5964

6065
def bind(self, service):
6166
"""Binds the characteristic to the given Service."""
6267
bound_characteristic = super().bind(service)
63-
return _bleio.PacketBuffer(bound_characteristic,
64-
buffer_size=1)
68+
return _bleio.PacketBuffer(bound_characteristic, buffer_size=1)
69+
6570

6671
class _EntityUpdate(ComplexCharacteristic):
6772
"""UTF-8 Encoded string characteristic."""
73+
6874
uuid = VendorUUID("2F7CABCE-808D-411F-9A0C-BB92BA96C102")
6975

7076
def __init__(self):
71-
super().__init__(properties=Characteristic.WRITE | Characteristic.NOTIFY,
72-
read_perm=Attribute.OPEN, write_perm=Attribute.OPEN,
73-
max_length=128,
74-
fixed_length=False)
75-
77+
super().__init__(
78+
properties=Characteristic.WRITE | Characteristic.NOTIFY,
79+
read_perm=Attribute.OPEN,
80+
write_perm=Attribute.OPEN,
81+
max_length=128,
82+
fixed_length=False,
83+
)
7684

7785
def bind(self, service):
7886
"""Binds the characteristic to the given Service."""
7987
bound_characteristic = super().bind(service)
80-
return _bleio.PacketBuffer(bound_characteristic,
81-
buffer_size=8)
88+
return _bleio.PacketBuffer(bound_characteristic, buffer_size=8)
89+
8290

83-
class _EntityAttribute(Characteristic): # pylint: disable=too-few-public-methods
91+
class _EntityAttribute(Characteristic): # pylint: disable=too-few-public-methods
8492
"""UTF-8 Encoded string characteristic."""
93+
8594
uuid = VendorUUID("C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7")
8695

8796
def __init__(self):
88-
super().__init__(properties=Characteristic.WRITE | Characteristic.READ,
89-
read_perm=Attribute.OPEN, write_perm=Attribute.OPEN,
90-
fixed_length=False)
97+
super().__init__(
98+
properties=Characteristic.WRITE | Characteristic.READ,
99+
read_perm=Attribute.OPEN,
100+
write_perm=Attribute.OPEN,
101+
fixed_length=False,
102+
)
103+
91104

92105
class _MediaAttribute:
93106
def __init__(self, entity_id, attribute_id):
@@ -103,7 +116,11 @@ def _update(obj):
103116
raise RuntimeError("packet too short")
104117
# Even though flags is currently unused, if it were removed, it would cause there to be
105118
# too many values to unpack which would raise a ValueError
106-
entity_id, attribute_id, flags = struct.unpack_from("<BBB", obj._buffer) # pylint: disable=unused-variable
119+
(
120+
entity_id,
121+
attribute_id,
122+
flags, # pylint: disable=unused-variable
123+
) = struct.unpack_from("<BBB", obj._buffer)
107124
value = str(obj._buffer[3:length_read], "utf-8")
108125
obj._attribute_cache[(entity_id, attribute_id)] = value
109126

@@ -114,13 +131,14 @@ def __get__(self, obj, cls):
114131
for k in obj._attribute_cache:
115132
if k[0] == self.key[0] and k[1] not in siblings:
116133
siblings.append(k[1])
117-
buf = struct.pack("<B" + "B"*len(siblings), self.key[0], *siblings)
134+
buf = struct.pack("<B" + "B" * len(siblings), self.key[0], *siblings)
118135
obj._entity_update.write(buf)
119136
obj._attribute_cache[self.key] = None
120137
time.sleep(0.05)
121138
self._update(obj)
122139
return obj._attribute_cache[self.key]
123140

141+
124142
class _MediaAttributePlaybackState:
125143
def __init__(self, playback_value):
126144
self._playback_value = playback_value
@@ -131,6 +149,7 @@ def __get__(self, obj, cls):
131149
return int(info.split(",")[0]) == self._playback_value
132150
return False
133151

152+
134153
class _MediaAttributePlaybackInfo:
135154
def __init__(self, position):
136155
self._position = position
@@ -141,9 +160,11 @@ def __get__(self, obj, cls):
141160
return float(info.split(",")[self._position])
142161
return 0
143162

163+
144164
class UnsupportedCommand(Exception):
145165
"""Raised when the command isn't available with current media player app."""
146166

167+
147168
class AppleMediaService(Service):
148169
"""View and control currently playing media.
149170
@@ -152,6 +173,7 @@ class AppleMediaService(Service):
152173
`artist` includes a description of the remote playback.
153174
154175
"""
176+
155177
uuid = VendorUUID("89D3502B-0F36-433A-8EF4-C502AD55F8DC")
156178

157179
_remote_command = _RemoteCommand()
@@ -207,7 +229,9 @@ def __init__(self, **kwargs):
207229
def _send_command(self, command_id):
208230
if not self._command_buffer:
209231
self._command_buffer = bytearray(13)
210-
i = self._remote_command.readinto(self._command_buffer) # pylint: disable=no-member
232+
i = self._remote_command.readinto( # pylint: disable=no-member
233+
self._command_buffer
234+
)
211235
if i > 0:
212236
self._supported_commands = list(self._command_buffer[:i])
213237
if command_id not in self._supported_commands:
@@ -217,7 +241,7 @@ def _send_command(self, command_id):
217241
if not self._cmd:
218242
self._cmd = bytearray(1)
219243
self._cmd[0] = command_id
220-
self._remote_command.write(self._cmd) # pylint: disable=no-member
244+
self._remote_command.write(self._cmd) # pylint: disable=no-member
221245

222246
def play(self):
223247
"""Plays the current track. Does nothing if already playing."""

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# Uncomment the below if you use native CircuitPython modules such as
@@ -22,29 +23,32 @@
2223
# autodoc_mock_imports = []
2324

2425

25-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
26+
intersphinx_mapping = {
27+
"python": ("https://docs.python.org/3.4", None),
28+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
29+
}
2630

2731
# Add any paths that contain templates here, relative to this directory.
28-
templates_path = ['_templates']
32+
templates_path = ["_templates"]
2933

30-
source_suffix = '.rst'
34+
source_suffix = ".rst"
3135

3236
# The master toctree document.
33-
master_doc = 'index'
37+
master_doc = "index"
3438

3539
# General information about the project.
36-
project = u'Adafruit BLE_Apple_Media Library'
37-
copyright = u'2020 Scott Shawcroft'
38-
author = u'Scott Shawcroft'
40+
project = "Adafruit BLE_Apple_Media Library"
41+
copyright = "2020 Scott Shawcroft"
42+
author = "Scott Shawcroft"
3943

4044
# The version info for the project you're documenting, acts as replacement for
4145
# |version| and |release|, also used in various other places throughout the
4246
# built documents.
4347
#
4448
# The short X.Y version.
45-
version = u'1.0'
49+
version = "1.0"
4650
# The full version, including alpha/beta/rc tags.
47-
release = u'1.0'
51+
release = "1.0"
4852

4953
# The language for content autogenerated by Sphinx. Refer to documentation
5054
# for a list of supported languages.
@@ -56,7 +60,7 @@
5660
# List of patterns, relative to source directory, that match files and
5761
# directories to ignore when looking for source files.
5862
# This patterns also effect to html_static_path and html_extra_path
59-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
63+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6064

6165
# The reST default role (used for this markup: `text`) to use for all
6266
# documents.
@@ -68,7 +72,7 @@
6872
add_function_parentheses = True
6973

7074
# The name of the Pygments (syntax highlighting) style to use.
71-
pygments_style = 'sphinx'
75+
pygments_style = "sphinx"
7276

7377
# If true, `todo` and `todoList` produce output, else they produce nothing.
7478
todo_include_todos = False
@@ -83,68 +87,76 @@
8387
# The theme to use for HTML and HTML Help pages. See the documentation for
8488
# a list of builtin themes.
8589
#
86-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
90+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8791

8892
if not on_rtd: # only import and set the theme if we're building docs locally
8993
try:
9094
import sphinx_rtd_theme
91-
html_theme = 'sphinx_rtd_theme'
92-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
95+
96+
html_theme = "sphinx_rtd_theme"
97+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9398
except:
94-
html_theme = 'default'
95-
html_theme_path = ['.']
99+
html_theme = "default"
100+
html_theme_path = ["."]
96101
else:
97-
html_theme_path = ['.']
102+
html_theme_path = ["."]
98103

99104
# Add any paths that contain custom static files (such as style sheets) here,
100105
# relative to this directory. They are copied after the builtin static files,
101106
# so a file named "default.css" will overwrite the builtin "default.css".
102-
html_static_path = ['_static']
107+
html_static_path = ["_static"]
103108

104109
# The name of an image file (relative to this directory) to use as a favicon of
105110
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
106111
# pixels large.
107112
#
108-
html_favicon = '_static/favicon.ico'
113+
html_favicon = "_static/favicon.ico"
109114

110115
# Output file base name for HTML help builder.
111-
htmlhelp_basename = 'AdafruitBle_apple_mediaLibrarydoc'
116+
htmlhelp_basename = "AdafruitBle_apple_mediaLibrarydoc"
112117

113118
# -- Options for LaTeX output ---------------------------------------------
114119

115120
latex_elements = {
116-
# The paper size ('letterpaper' or 'a4paper').
117-
#
118-
# 'papersize': 'letterpaper',
119-
120-
# The font size ('10pt', '11pt' or '12pt').
121-
#
122-
# 'pointsize': '10pt',
123-
124-
# Additional stuff for the LaTeX preamble.
125-
#
126-
# 'preamble': '',
127-
128-
# Latex figure (float) alignment
129-
#
130-
# 'figure_align': 'htbp',
121+
# The paper size ('letterpaper' or 'a4paper').
122+
#
123+
# 'papersize': 'letterpaper',
124+
# The font size ('10pt', '11pt' or '12pt').
125+
#
126+
# 'pointsize': '10pt',
127+
# Additional stuff for the LaTeX preamble.
128+
#
129+
# 'preamble': '',
130+
# Latex figure (float) alignment
131+
#
132+
# 'figure_align': 'htbp',
131133
}
132134

133135
# Grouping the document tree into LaTeX files. List of tuples
134136
# (source start file, target name, title,
135137
# author, documentclass [howto, manual, or own class]).
136138
latex_documents = [
137-
(master_doc, 'AdafruitBLE_Apple_MediaLibrary.tex', u'AdafruitBLE_Apple_Media Library Documentation',
138-
author, 'manual'),
139+
(
140+
master_doc,
141+
"AdafruitBLE_Apple_MediaLibrary.tex",
142+
"AdafruitBLE_Apple_Media Library Documentation",
143+
author,
144+
"manual",
145+
),
139146
]
140147

141148
# -- Options for manual page output ---------------------------------------
142149

143150
# One entry per manual page. List of tuples
144151
# (source start file, name, description, authors, manual section).
145152
man_pages = [
146-
(master_doc, 'AdafruitBLE_Apple_Medialibrary', u'Adafruit BLE_Apple_Media Library Documentation',
147-
[author], 1)
153+
(
154+
master_doc,
155+
"AdafruitBLE_Apple_Medialibrary",
156+
"Adafruit BLE_Apple_Media Library Documentation",
157+
[author],
158+
1,
159+
)
148160
]
149161

150162
# -- Options for Texinfo output -------------------------------------------
@@ -153,7 +165,13 @@
153165
# (source start file, target name, title, author,
154166
# dir menu entry, description, category)
155167
texinfo_documents = [
156-
(master_doc, 'AdafruitBLE_Apple_MediaLibrary', u'Adafruit BLE_Apple_Media Library Documentation',
157-
author, 'AdafruitBLE_Apple_MediaLibrary', 'One line description of project.',
158-
'Miscellaneous'),
168+
(
169+
master_doc,
170+
"AdafruitBLE_Apple_MediaLibrary",
171+
"Adafruit BLE_Apple_Media Library Documentation",
172+
author,
173+
"AdafruitBLE_Apple_MediaLibrary",
174+
"One line description of project.",
175+
"Miscellaneous",
176+
),
159177
]

examples/ble_apple_media_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from adafruit_ble_apple_media import AppleMediaService
1010

1111
# PyLint can't find BLERadio for some reason so special case it here.
12-
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
12+
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
1313
a = SolicitServicesAdvertisement()
1414
a.solicited_services.append(AppleMediaService)
1515
radio.start_advertising(a)

0 commit comments

Comments
 (0)