Skip to content

Lint and doc #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deploy:
install:
- pip install -r requirements.txt
- pip install circuitpython-build-tools Sphinx sphinx-rtd-theme
- pip install --force-reinstall pylint==1.9.2
- pip install --force-reinstall "pylint<3"

script:
- pylint adafruit_ble_apple_notification_center.py
Expand Down
39 changes: 38 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,44 @@ To install in a virtual environment in your current project:
Usage Example
=============

.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
.. code::python

"""
This example solicits that apple devices that provide notifications connect to it, initiates
pairing, and prints existing notifications.
"""

import adafruit_ble
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
import adafruit_ble_apple_notification_center as ancs

radio = adafruit_ble.BLERadio()
a = SolicitServicesAdvertisement()
a.solicited_services.append(ancs.AppleNotificationCenterService)
radio.start_advertising(a)

print("Waiting for connection")

while not radio.connected:
pass

print("Connected")

for connection in radio.connections:
if ancs.AppleNotificationCenterService not in connection:
continue

if not connection.paired:
connection.pair()
print("Paired")

ans = connection[ancs.AppleNotificationCenterService]
# Wait for the notifications to load.
while len(ans.active_notifications) == 0:
pass
for notification_id in ans.active_notifications:
notification = ans.active_notifications[notification_id]
print(notification.app_id, notification.title)

Contributing
============
Expand Down
3 changes: 2 additions & 1 deletion adafruit_ble_apple_notification_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def __str__(self):
class AppleNotificationCenterService(Service):
"""Notification service.

Documented by Apple here: https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html
Documented by Apple here:
https://developer.apple.com/library/archive/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Specification/Specification.html

"""
uuid = VendorUUID("7905F431-B5CE-4E99-A40F-4B1E122D00D0")
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio", "busio"]
autodoc_mock_imports = ["adafruit_ble"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
Expand Down
7 changes: 2 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ Table of Contents
.. toctree::
:caption: Tutorials

.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
the toctree above for use later.

.. toctree::
:caption: Related Products

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

.. toctree::
:caption: Other Links
Expand Down
36 changes: 36 additions & 0 deletions examples/ble_apple_notification_center_new.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
This example solicits that apple devices that provide notifications connect to it, initiates
pairing, prints existing notifications and then prints any new ones as they arrive.
"""

import time
import adafruit_ble
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
import adafruit_ble_apple_notification_center as ancs

radio = adafruit_ble.BLERadio()
a = SolicitServicesAdvertisement()
a.solicited_services.append(ancs.AppleNotificationCenterService)
radio.start_advertising(a)

while not radio.connected:
pass

print("connected")

known_notifications = set()

while radio.connected:
for connection in radio.connections:
if not connection.paired:
connection.pair()
print("paired")

ans = connection[ancs.AppleNotificationCenterService]
for notification in ans.wait_for_new_notifications():
print(notification)

print(len(ans.active_notifications))
time.sleep(1)

print("disconnected")
32 changes: 17 additions & 15 deletions examples/ble_apple_notification_center_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""
This example solicits that apple devices that provide notifications connect to it, initiates
pairing, prints existing notifications and then prints any new ones as they arrive.
pairing, and prints existing notifications.
"""

import time
import adafruit_ble
from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
import adafruit_ble_apple_notification_center as ancs
Expand All @@ -13,22 +12,25 @@
a.solicited_services.append(ancs.AppleNotificationCenterService)
radio.start_advertising(a)

print("Waiting for connection")

while not radio.connected:
pass

print("connected")

known_notifications = set()
print("Connected")

while radio.connected:
for connection in radio.connections:
if not connection.paired:
connection.pair()
print("paired")
for connection in radio.connections:
if ancs.AppleNotificationCenterService not in connection:
continue

ans = connection[ancs.AppleNotificationCenterService]
for notification in ans.wait_for_new_notifications():
print(notification)
time.sleep(1)
if not connection.paired:
connection.pair()
print("Paired")

print("disconnected")
ans = connection[ancs.AppleNotificationCenterService]
# Wait for the notifications to load.
while len(ans.active_notifications) == 0:
pass
for notification_id in ans.active_notifications:
notification = ans.active_notifications[notification_id]
print(notification.app_id, notification.title)
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
Adafruit-Blinka
adafruit-circuitpython-ble