Skip to content

Commit bf2d5c5

Browse files
authored
Merge pull request #1 from tannewt/lint
Lint and doc
2 parents 42f8205 + 07ba24e commit bf2d5c5

8 files changed

+97
-26
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ 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:
4545
- pylint adafruit_ble_apple_notification_center.py

README.rst

+38-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,44 @@ To install in a virtual environment in your current project:
5656
Usage Example
5757
=============
5858

59-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
59+
.. code::python
60+
61+
"""
62+
This example solicits that apple devices that provide notifications connect to it, initiates
63+
pairing, and prints existing notifications.
64+
"""
65+
66+
import adafruit_ble
67+
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
68+
import adafruit_ble_apple_notification_center as ancs
69+
70+
radio = adafruit_ble.BLERadio()
71+
a = SolicitServicesAdvertisement()
72+
a.solicited_services.append(ancs.AppleNotificationCenterService)
73+
radio.start_advertising(a)
74+
75+
print("Waiting for connection")
76+
77+
while not radio.connected:
78+
pass
79+
80+
print("Connected")
81+
82+
for connection in radio.connections:
83+
if ancs.AppleNotificationCenterService not in connection:
84+
continue
85+
86+
if not connection.paired:
87+
connection.pair()
88+
print("Paired")
89+
90+
ans = connection[ancs.AppleNotificationCenterService]
91+
# Wait for the notifications to load.
92+
while len(ans.active_notifications) == 0:
93+
pass
94+
for notification_id in ans.active_notifications:
95+
notification = ans.active_notifications[notification_id]
96+
print(notification.app_id, notification.title)
6097
6198
Contributing
6299
============

adafruit_ble_apple_notification_center.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def __str__(self):
188188
class AppleNotificationCenterService(Service):
189189
"""Notification service.
190190
191-
Documented by Apple here: https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html
191+
Documented by Apple here:
192+
https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html
192193
193194
"""
194195
uuid = VendorUUID("7905F431-B5CE-4E99-A40F-4B1E122D00D0")

docs/conf.py

+1-1
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 = ["adafruit_ble"]
2424

2525

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

docs/index.rst

+2-5
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
This example solicits that apple devices that provide notifications connect to it, initiates
3+
pairing, prints existing notifications and then prints any new ones as they arrive.
4+
"""
5+
6+
import time
7+
import adafruit_ble
8+
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
9+
import adafruit_ble_apple_notification_center as ancs
10+
11+
radio = adafruit_ble.BLERadio()
12+
a = SolicitServicesAdvertisement()
13+
a.solicited_services.append(ancs.AppleNotificationCenterService)
14+
radio.start_advertising(a)
15+
16+
while not radio.connected:
17+
pass
18+
19+
print("connected")
20+
21+
known_notifications = set()
22+
23+
while radio.connected:
24+
for connection in radio.connections:
25+
if not connection.paired:
26+
connection.pair()
27+
print("paired")
28+
29+
ans = connection[ancs.AppleNotificationCenterService]
30+
for notification in ans.wait_for_new_notifications():
31+
print(notification)
32+
33+
print(len(ans.active_notifications))
34+
time.sleep(1)
35+
36+
print("disconnected")
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""
22
This example solicits that apple devices that provide notifications connect to it, initiates
3-
pairing, prints existing notifications and then prints any new ones as they arrive.
3+
pairing, and prints existing notifications.
44
"""
55

6-
import time
76
import adafruit_ble
87
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
98
import adafruit_ble_apple_notification_center as ancs
@@ -13,22 +12,25 @@
1312
a.solicited_services.append(ancs.AppleNotificationCenterService)
1413
radio.start_advertising(a)
1514

15+
print("Waiting for connection")
16+
1617
while not radio.connected:
1718
pass
1819

19-
print("connected")
20-
21-
known_notifications = set()
20+
print("Connected")
2221

23-
while radio.connected:
24-
for connection in radio.connections:
25-
if not connection.paired:
26-
connection.pair()
27-
print("paired")
22+
for connection in radio.connections:
23+
if ancs.AppleNotificationCenterService not in connection:
24+
continue
2825

29-
ans = connection[ancs.AppleNotificationCenterService]
30-
for notification in ans.wait_for_new_notifications():
31-
print(notification)
32-
time.sleep(1)
26+
if not connection.paired:
27+
connection.pair()
28+
print("Paired")
3329

34-
print("disconnected")
30+
ans = connection[ancs.AppleNotificationCenterService]
31+
# Wait for the notifications to load.
32+
while len(ans.active_notifications) == 0:
33+
pass
34+
for notification_id in ans.active_notifications:
35+
notification = ans.active_notifications[notification_id]
36+
print(notification.app_id, notification.title)

requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
Adafruit-Blinka
2-
adafruit-circuitpython-ble

0 commit comments

Comments
 (0)