Simple test

Ensure your device works with this simple test.

examples/ble_apple_notification_center_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example solicits that apple devices that provide notifications connect to it, initiates
 6pairing, and prints existing notifications.
 7"""
 8
 9import adafruit_ble
10from adafruit_ble.advertising.standard import SolicitServicesAdvertisement
11import adafruit_ble_apple_notification_center as ancs
12
13# PyLint can't find BLERadio for some reason so special case it here.
14radio = adafruit_ble.BLERadio()  # pylint: disable=no-member
15a = SolicitServicesAdvertisement()
16a.solicited_services.append(ancs.AppleNotificationCenterService)
17radio.start_advertising(a)
18
19print("Waiting for connection")
20
21while not radio.connected:
22    pass
23
24print("Connected")
25
26for connection in radio.connections:
27    if ancs.AppleNotificationCenterService not in connection:
28        continue
29
30    if not connection.paired:
31        connection.pair()
32        print("Paired")
33
34    ans = connection[ancs.AppleNotificationCenterService]
35    # Wait for the notifications to load.
36    while len(ans.active_notifications) == 0:
37        pass
38    for notification_id in ans.active_notifications:
39        notification = ans.active_notifications[notification_id]
40        print(notification.app_id, notification.title)