Skip to content

Commit 13b4703

Browse files
authored
Merge pull request #8 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 67f3d8b + 4469c4e commit 13b4703

File tree

5 files changed

+144
-107
lines changed

5 files changed

+144
-107
lines changed

adafruit_ble_apple_notification_center.py

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ def __get__(self, notification, cls):
6363
pass
6464

6565
_, _ = struct.unpack("<BI", notification.data_source.read(5))
66-
attribute_id, attribute_length = struct.unpack("<BH", notification.data_source.read(3))
66+
attribute_id, attribute_length = struct.unpack(
67+
"<BH", notification.data_source.read(3)
68+
)
6769
if attribute_id != self._id:
6870
raise RuntimeError("Data for other attribute")
6971
value = notification.data_source.read(attribute_length)
7072
value = value.decode("utf-8")
7173
notification._attribute_cache[self._id] = value
7274
return value
7375

76+
7477
NOTIFICATION_CATEGORIES = (
7578
"Other",
7679
"IncomingCall",
@@ -83,11 +86,13 @@ def __get__(self, notification, cls):
8386
"HealthAndFitness",
8487
"BusinessAndFinance",
8588
"Location",
86-
"Entertainment"
89+
"Entertainment",
8790
)
8891

92+
8993
class Notification:
9094
"""One notification that appears in the iOS notification center."""
95+
9196
# pylint: disable=too-many-instance-attributes
9297

9398
app_id = _NotificationAttribute(0)
@@ -113,15 +118,22 @@ class Notification:
113118
negative_action_label = _NotificationAttribute(7)
114119
"""Human readable label of the negative action."""
115120

116-
def __init__(self, notification_id, event_flags, category_id, category_count, *, control_point,
117-
data_source):
118-
self.id = notification_id # pylint: disable=invalid-name
121+
def __init__(
122+
self,
123+
notification_id,
124+
event_flags,
125+
category_id,
126+
category_count,
127+
*,
128+
control_point,
129+
data_source
130+
):
131+
self.id = notification_id # pylint: disable=invalid-name
119132
"""Integer id of the notification."""
120133

121134
self.removed = False
122135
"""True when the notification has been cleared on the iOS device."""
123136

124-
125137
self.silent = False
126138
self.important = False
127139
self.preexisting = False
@@ -178,12 +190,20 @@ def __str__(self):
178190
flags.append("positive_action")
179191
if self.negative_action:
180192
flags.append("negative_action")
181-
return (category + " " +
182-
" ".join(flags) + " " +
183-
self.app_id + " " +
184-
str(self.title) + " " +
185-
str(self.subtitle) + " " +
186-
str(self.message))
193+
return (
194+
category
195+
+ " "
196+
+ " ".join(flags)
197+
+ " "
198+
+ self.app_id
199+
+ " "
200+
+ str(self.title)
201+
+ " "
202+
+ str(self.subtitle)
203+
+ " "
204+
+ str(self.message)
205+
)
206+
187207

188208
class AppleNotificationCenterService(Service):
189209
"""Notification service.
@@ -192,32 +212,42 @@ class AppleNotificationCenterService(Service):
192212
https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html
193213
194214
"""
215+
195216
uuid = VendorUUID("7905F431-B5CE-4E99-A40F-4B1E122D00D0")
196217

197218
control_point = StreamIn(uuid=VendorUUID("69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9"))
198-
data_source = StreamOut(uuid=VendorUUID("22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB"),
199-
buffer_size=1024)
200-
notification_source = StreamOut(uuid=VendorUUID("9FBF120D-6301-42D9-8C58-25E699A21DBD"),
201-
buffer_size=8*100)
219+
data_source = StreamOut(
220+
uuid=VendorUUID("22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB"), buffer_size=1024
221+
)
222+
notification_source = StreamOut(
223+
uuid=VendorUUID("9FBF120D-6301-42D9-8C58-25E699A21DBD"), buffer_size=8 * 100
224+
)
202225

203226
def __init__(self, service=None):
204227
super().__init__(service=service)
205228
self._active_notifications = {}
206229

207230
def _update(self):
208231
# Pylint is incorrectly inferring the type of self.notification_source so disable no-member.
209-
while self.notification_source.in_waiting > 7: # pylint: disable=no-member
210-
buffer = self.notification_source.read(8) # pylint: disable=no-member
211-
event_id, event_flags, category_id, category_count, nid = struct.unpack("<BBBBI",
212-
buffer)
232+
while self.notification_source.in_waiting > 7: # pylint: disable=no-member
233+
buffer = self.notification_source.read(8) # pylint: disable=no-member
234+
event_id, event_flags, category_id, category_count, nid = struct.unpack(
235+
"<BBBBI", buffer
236+
)
213237
if event_id == 0:
214-
self._active_notifications[nid] = Notification(nid, event_flags, category_id,
215-
category_count,
216-
control_point=self.control_point,
217-
data_source=self.data_source)
238+
self._active_notifications[nid] = Notification(
239+
nid,
240+
event_flags,
241+
category_id,
242+
category_count,
243+
control_point=self.control_point,
244+
data_source=self.data_source,
245+
)
218246
yield self._active_notifications[nid]
219247
elif event_id == 1:
220-
self._active_notifications[nid].update(event_flags, category_id, category_count)
248+
self._active_notifications[nid].update(
249+
event_flags, category_id, category_count
250+
)
221251
yield None
222252
elif event_id == 2:
223253
self._active_notifications[nid].removed = True

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
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
autodoc_mock_imports = []
2425

2526

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

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit BLE_Apple_Notification_Center Library'
38-
copyright = u'2019 Scott Shawcroft'
39-
author = u'Scott Shawcroft'
41+
project = u"Adafruit BLE_Apple_Notification_Center Library"
42+
copyright = u"2019 Scott Shawcroft"
43+
author = u"Scott Shawcroft"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = u"1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = u"1.0"
4953

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

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

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

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

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

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

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitBle_apple_notification_centerLibrarydoc'
117+
htmlhelp_basename = "AdafruitBle_apple_notification_centerLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

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

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

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

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitBLE_Apple_Notification_Centerlibrary', u'Adafruit BLE_Apple_Notification_Center Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitBLE_Apple_Notification_Centerlibrary",
157+
u"Adafruit BLE_Apple_Notification_Center Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitBLE_Apple_Notification_CenterLibrary', u'Adafruit BLE_Apple_Notification_Center Library Documentation',
158-
author, 'AdafruitBLE_Apple_Notification_CenterLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitBLE_Apple_Notification_CenterLibrary",
172+
u"Adafruit BLE_Apple_Notification_Center Library Documentation",
173+
author,
174+
"AdafruitBLE_Apple_Notification_CenterLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/ble_apple_notification_center_new.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import adafruit_ble_apple_notification_center as ancs
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(ancs.AppleNotificationCenterService)
1515
radio.start_advertising(a)

examples/ble_apple_notification_center_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import adafruit_ble_apple_notification_center as ancs
99

1010
# PyLint can't find BLERadio for some reason so special case it here.
11-
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
11+
radio = adafruit_ble.BLERadio() # pylint: disable=no-member
1212
a = SolicitServicesAdvertisement()
1313
a.solicited_services.append(ancs.AppleNotificationCenterService)
1414
radio.start_advertising(a)

0 commit comments

Comments
 (0)