2
2
#
3
3
# SPDX-License-Identifier: MIT
4
4
5
- from __future__ import annotations
6
-
7
5
"""
8
6
`adafruit_ble_apple_notification_center`
9
7
================================================================================
19
17
* Adafruit's BLE library: https://github.com/adafruit/Adafruit_CircuitPython_BLE
20
18
"""
21
19
20
+ from __future__ import annotations
21
+
22
22
import struct
23
23
import time
24
24
25
25
try :
26
- from typing import Generator , Union , Dict
26
+ from typing import Generator , Union , Dict , Optional , Any
27
27
except ImportError :
28
28
pass
29
29
36
36
37
37
38
38
class _NotificationAttribute :
39
- def __init__ (self , attribute_id : int , * , max_length : bool = False ) -> None :
39
+ def __init__ (self , attribute_id : int , * , max_length : bool = False ) -> None :
40
40
self ._id = attribute_id
41
41
self ._max_length = max_length
42
42
43
- def __get__ (self , notification : Notification , cls ) -> int :
43
+ def __get__ (self , notification : Notification , cls : Any ) -> str :
44
44
if self ._id in notification ._attribute_cache :
45
45
return notification ._attribute_cache [self ._id ]
46
46
@@ -117,7 +117,7 @@ def __init__(
117
117
category_count : int ,
118
118
* ,
119
119
control_point : StreamIn ,
120
- data_source : StreamOut
120
+ data_source : StreamOut ,
121
121
) -> None :
122
122
self .id = notification_id # pylint: disable=invalid-name
123
123
"""Integer id of the notification."""
@@ -143,7 +143,7 @@ def __init__(
143
143
144
144
self .update (event_flags , category_id , category_count )
145
145
146
- self ._attribute_cache : Dict [int ] = {}
146
+ self ._attribute_cache : Dict [int , str ] = {}
147
147
148
148
self .control_point = control_point
149
149
self .data_source = data_source
@@ -230,11 +230,11 @@ class AppleNotificationCenterService(Service):
230
230
uuid = VendorUUID ("9FBF120D-6301-42D9-8C58-25E699A21DBD" ), buffer_size = 8 * 100
231
231
)
232
232
233
- def __init__ (self , service : Service = None ) -> None :
233
+ def __init__ (self , service : Service = None ) -> None :
234
234
super ().__init__ (service = service )
235
- self ._active_notifications = {}
235
+ self ._active_notifications : Dict [ tuple , Notification ] = {}
236
236
237
- def _update (self ) -> Generator [Union [int , None ], None , None ]:
237
+ def _update (self ) -> Generator [Union [Notification , None ], None , None ]:
238
238
# Pylint is incorrectly inferring the type of self.notification_source so disable no-member.
239
239
while self .notification_source .in_waiting > 7 : # pylint: disable=no-member
240
240
buffer = self .notification_source .read (8 ) # pylint: disable=no-member
@@ -261,7 +261,9 @@ def _update(self) -> Generator[Union[int, None], None, None]:
261
261
del self ._active_notifications [nid ]
262
262
yield None
263
263
264
- def wait_for_new_notifications (self , timeout : float = None ) -> Generator [Union [int , None ], None , None ]:
264
+ def wait_for_new_notifications (
265
+ self , timeout : Optional [float ] = None
266
+ ) -> Generator [Union [Notification , None ], None , None ]:
265
267
"""Waits for new notifications and yields them. Returns on timeout, update, disconnect or
266
268
clear."""
267
269
start_time = time .monotonic ()
0 commit comments