Skip to content

Commit 6b1bb57

Browse files
authored
Merge pull request #1 from tannewt/lint
Lint
2 parents c881874 + 94c3d88 commit 6b1bb57

File tree

9 files changed

+69
-51
lines changed

9 files changed

+69
-51
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ deploy:
3939
install:
4040
- pip install -r requirements.txt
4141
- pip install circuitpython-build-tools Sphinx sphinx-rtd-theme
42-
- pip install --force-reinstall pylint==1.9.2
42+
- pip install --force-reinstall "pylint<3"
4343

4444
script:
45-
- pylint adafruit_display_notification.py
45+
- pylint adafruit_display_notification/*.py
4646
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py)
4747
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-display_notification --library_location .
4848
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

README.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ Installing from PyPI
3131
.. note:: This library is not available on PyPI yet. Install documentation is included
3232
as a standard element. Stay tuned for PyPI availability!
3333

34-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
35-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
36-
3734
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
3835
PyPI <https://pypi.org/project/adafruit-circuitpython-display_notification/>`_. To install for current user:
3936

@@ -59,7 +56,7 @@ To install in a virtual environment in your current project:
5956
Usage Example
6057
=============
6158

62-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
59+
See the `examples` folder.
6360

6461
Contributing
6562
============

adafruit_display_notification/__init__.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,31 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23+
"""
24+
`adafruit_display_notification`
25+
================================================================================
26+
27+
Very basic notification widgets.
28+
29+
"""
30+
2331
import displayio
2432

25-
from adafruit_bitmap_font import bitmap_font
2633
from adafruit_display_text import label
2734

2835
import terminalio
2936

3037
__version__ = "0.0.0-auto.0"
3138
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git"
3239

33-
#text_font = bitmap_font.load_font("/Helvetica-Bold-16.bdf")
34-
text_font = terminalio.FONT
40+
TEXT_FONT = terminalio.FONT
41+
42+
# pylint: disable=too-few-public-methods
3543

3644
class NotificationFree(displayio.Group):
45+
"""Widget to show when no notifications are active."""
3746
def __init__(self, width, height, *, dark_mode=True):
47+
# pylint: disable=unused-argument
3848
super().__init__()
3949

4050
if dark_mode:
@@ -43,35 +53,39 @@ def __init__(self, width, height, *, dark_mode=True):
4353
text_color = 0x000000
4454

4555
# Create the text label
46-
self.title = label.Label(text_font, text="None!", y=height//2, color=text_color)
56+
self.title = label.Label(TEXT_FONT, text="None!", y=height//2, color=text_color)
4757
self.append(self.title)
4858

4959
class PlainNotification(displayio.Group):
60+
"""Plain text widget with a title and message."""
5061
def __init__(self, title, message, width, height, *, dark_mode=True):
5162
super().__init__()
5263

53-
#Create group holding text
54-
text_group = displayio.Group(max_size=10, scale=1)
5564
# Set text, font, and color
5665
if dark_mode:
5766
text_color = 0xffffff
5867
else:
5968
text_color = 0x000000
6069

6170
# Create the text label
62-
self.title = label.Label(text_font, text=title, color=text_color, y=8)
71+
self.title = label.Label(TEXT_FONT, text=title, color=text_color, y=8)
6372
self.append(self.title)
6473

6574
# TODO: Move this into Label or a TextBox.
66-
lines = self._wrap_nicely(message, width // 7)
75+
lines = PlainNotification._wrap_nicely(message, width // 7)
6776
max_lines = height // 20
6877
message = "\n".join(lines[:max_lines])
6978

70-
self.message = label.Label(terminalio.FONT, text=message, color=text_color, x=2, y=height//2 + 8)
79+
self.message = label.Label(terminalio.FONT,
80+
text=message,
81+
color=text_color,
82+
x=2,
83+
y=height // 2 + 8)
7184
self.append(self.message)
7285

7386
# cribbed from pyportal
74-
def _wrap_nicely(self, string, max_chars):
87+
@staticmethod
88+
def _wrap_nicely(string, max_chars):
7589
"""A helper that will return a list of lines with word-break wrapping.
7690
:param str string: The text to be wrapped.
7791
:param int max_chars: The maximum number of characters on a line before wrapping.

adafruit_display_notification/apple.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23+
"""
24+
`adafruit_display_notification.apple`
25+
================================================================================
26+
27+
Maps Apple Notification Center Notification objects to the notification widgets
28+
in this library.
29+
30+
"""
31+
2332
from . import PlainNotification
2433

2534
__version__ = "0.0.0-auto.0"
2635
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Notification.git"
2736

2837
def create_notification_widget(notification, max_width, max_height, *, color_count=2**16):
2938
"""Creates a notification widget for the given Apple notification."""
39+
# pylint: disable=unused-argument
3040
return PlainNotification(notification.title, notification.message, max_width, max_height)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Uncomment the below if you use native CircuitPython modules such as
2121
# digitalio, micropython and busio. List the modules you use. Without it, the
2222
# autodoc module docs will fail to generate with a warning.
23-
# autodoc_mock_imports = ["digitalio", "busio"]
23+
autodoc_mock_imports = ["displayio", "adafruit_bitmap_font", "adafruit_display_text", "terminalio"]
2424

2525

2626
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}

docs/index.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
28-
2926
.. toctree::
3027
:caption: Related Products
3128

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
29+
CircuitPlayground Bluefruit <https://www.adafruit.com/product/4333>
30+
Feather nRF52840 <https://www.adafruit.com/product/4062>
3431

3532
.. toctree::
3633
:caption: Other Links

examples/display_notification_eink_gizmo.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
"""This demo shows the latest notification from a connected Apple device on the EInk screen."""
22

3-
import board
4-
import displayio
5-
import terminalio
6-
import time
7-
83
import adafruit_ble
94
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
10-
from adafruit_ble.services.apple import AppleNotificationService
5+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
116
from adafruit_display_notification import apple
127
from adafruit_display_notification import NotificationFree
138
from adafruit_display_ble_status.advertising import AdvertisingWidget
@@ -18,22 +13,21 @@
1813

1914
def find_connection():
2015
for connection in radio.connections:
21-
if AppleNotificationService not in connection:
16+
if AppleNotificationCenterService not in connection:
2217
continue
2318
if not connection.paired:
2419
connection.pair()
25-
return connection, connection[AppleNotificationService]
20+
return connection, connection[AppleNotificationCenterService]
2621
return None, None
2722

2823
# Start advertising before messing with the display so that we can connect immediately.
2924
radio = adafruit_ble.BLERadio()
3025
a = SolicitServicesAdvertisement()
31-
a.complete_name = "CIRCUITPY"
32-
a.solicited_services.append(AppleNotificationService)
26+
a.solicited_services.append(AppleNotificationCenterService)
3327

3428
display = eink_gizmo.EInk_Gizmo()
3529

36-
radio_widget = AdvertisingWidget("CIRCUITPY", display.width, display.height)
30+
radio_widget = AdvertisingWidget(radio.name, display.width, display.height)
3731
display.show(radio_widget)
3832

3933
# True when the screen reflects our current state.
@@ -61,6 +55,8 @@ def find_connection():
6155
# Filter notifications we don't care about.
6256
if APPS and notification.app_id not in APPS:
6357
continue
58+
# For now, use _raw_date even though we should use a parsed version of the date.
59+
# pylint: disable=protected-access
6460
# Ignore notifications older than the currently shown one.
6561
if latest_notification and notification._raw_date < latest_notification._raw_date:
6662
continue
@@ -71,15 +67,17 @@ def find_connection():
7167
print(new_notification)
7268
latest_notification = new_notification
7369
screen_updated = False
74-
display.show(apple.create_notification_widget(latest_notification, display.width, display.height))
70+
display.show(apple.create_notification_widget(latest_notification,
71+
display.width,
72+
display.height))
7573
elif latest_notification and latest_notification.removed:
7674
# Stop showing the latest and show that there are no new notifications.
7775
latest_notification = None
7876
screen_updated = False
79-
display.show(NotificationFree())
77+
display.show(NotificationFree(display.width, display.height))
8078

81-
# Do not refresh the screen more often than every 180 seconds for eInk displays! Rapid refreshes
82-
# will damage the panel.
79+
# Do not refresh the screen more often than every 180 seconds for eInk displays! Rapid
80+
# refreshes will damage the panel.
8381
if not screen_updated and display.time_to_refresh == 0:
8482
display.refresh()
8583
screen_updated = True

examples/display_notification_simpletest.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
notifications.
55
"""
66

7+
import time
78
import board
89
import digitalio
910
import displayio
10-
import time
1111

1212
import adafruit_ble
1313
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
14-
from adafruit_ble.services.apple import AppleNotificationService
14+
from adafruit_ble_apple_notification_center import AppleNotificationCenterService
1515
from adafruit_display_notification import apple
1616
from adafruit_display_notification import NotificationFree
1717
from adafruit_display_ble_status.advertising import AdvertisingWidget
@@ -32,18 +32,17 @@
3232

3333
def find_connection():
3434
for connection in radio.connections:
35-
if AppleNotificationService not in connection:
35+
if AppleNotificationCenterService not in connection:
3636
continue
3737
if not connection.paired:
3838
connection.pair()
39-
return connection, connection[AppleNotificationService]
39+
return connection, connection[AppleNotificationCenterService]
4040
return None, None
4141

4242
# Start advertising before messing with the display so that we can connect immediately.
4343
radio = adafruit_ble.BLERadio()
4444
advertisement = SolicitServicesAdvertisement()
45-
advertisement.complete_name = "CIRCUITPY"
46-
advertisement.solicited_services.append(AppleNotificationService)
45+
advertisement.solicited_services.append(AppleNotificationCenterService)
4746

4847
SCALE = 2
4948

@@ -71,12 +70,14 @@ def find_connection():
7170
while active_connection.connected:
7271
all_ids.clear()
7372
current_notifications = notification_service.active_notifications
74-
for id in current_notifications:
75-
notification = current_notifications[id]
73+
for notification_id in current_notifications:
74+
notification = current_notifications[notification_id]
7675
if APPS and notification.app_id not in APPS:
7776
continue
78-
all_ids.append(id)
77+
all_ids.append(notification_id)
7978

79+
# For now, use _raw_date even though we should use a parsed version of the date.
80+
# pylint: disable=protected-access
8081
all_ids.sort(key=lambda x: current_notifications[x]._raw_date)
8182

8283
if current_notification and current_notification.removed:
@@ -87,7 +88,9 @@ def find_connection():
8788
group[0] = NotificationFree(width, height)
8889
elif all_ids:
8990
now = time.monotonic()
90-
if current_notification and current_notification.id in all_ids and now - last_press < DELAY_AFTER_PRESS:
91+
if (current_notification and
92+
current_notification.id in all_ids and
93+
now - last_press < DELAY_AFTER_PRESS):
9194
index = all_ids.index(current_notification.id)
9295
else:
9396
index = len(all_ids) - 1
@@ -99,9 +102,9 @@ def find_connection():
99102
last_press = now
100103
index += 1
101104

102-
id = all_ids[index]
103-
if not current_notification or current_notification.id != id:
104-
current_notification = current_notifications[id]
105+
notification_id = all_ids[index]
106+
if not current_notification or current_notification.id != notification_id:
107+
current_notification = current_notifications[notification_id]
105108
print(current_notification._raw_date, current_notification)
106109
group[0] = apple.create_notification_widget(current_notification, width, height)
107110

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Adafruit-Blinka
21
adafruit-circuitpython-display-text

0 commit comments

Comments
 (0)