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