Skip to content

Commit 94e62b6

Browse files
Adding type annotations per Issue #14
1 parent e328e07 commit 94e62b6

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

adafruit_ble_apple_notification_center.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
from __future__ import annotations
6-
75
"""
86
`adafruit_ble_apple_notification_center`
97
================================================================================
@@ -19,11 +17,13 @@
1917
* Adafruit's BLE library: https://github.com/adafruit/Adafruit_CircuitPython_BLE
2018
"""
2119

20+
from __future__ import annotations
21+
2222
import struct
2323
import time
2424

2525
try:
26-
from typing import Generator, Union, Dict
26+
from typing import Generator, Union, Dict, Optional, Any
2727
except ImportError:
2828
pass
2929

@@ -36,11 +36,11 @@
3636

3737

3838
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:
4040
self._id = attribute_id
4141
self._max_length = max_length
4242

43-
def __get__(self, notification: Notification, cls) -> int:
43+
def __get__(self, notification: Notification, cls: Any) -> str:
4444
if self._id in notification._attribute_cache:
4545
return notification._attribute_cache[self._id]
4646

@@ -117,7 +117,7 @@ def __init__(
117117
category_count: int,
118118
*,
119119
control_point: StreamIn,
120-
data_source: StreamOut
120+
data_source: StreamOut,
121121
) -> None:
122122
self.id = notification_id # pylint: disable=invalid-name
123123
"""Integer id of the notification."""
@@ -143,7 +143,7 @@ def __init__(
143143

144144
self.update(event_flags, category_id, category_count)
145145

146-
self._attribute_cache: Dict[int] = {}
146+
self._attribute_cache: Dict[int, str] = {}
147147

148148
self.control_point = control_point
149149
self.data_source = data_source
@@ -230,11 +230,11 @@ class AppleNotificationCenterService(Service):
230230
uuid=VendorUUID("9FBF120D-6301-42D9-8C58-25E699A21DBD"), buffer_size=8 * 100
231231
)
232232

233-
def __init__(self, service: Service=None) -> None:
233+
def __init__(self, service: Service = None) -> None:
234234
super().__init__(service=service)
235-
self._active_notifications = {}
235+
self._active_notifications: Dict[tuple, Notification] = {}
236236

237-
def _update(self) -> Generator[Union[int, None], None, None]:
237+
def _update(self) -> Generator[Union[Notification, None], None, None]:
238238
# Pylint is incorrectly inferring the type of self.notification_source so disable no-member.
239239
while self.notification_source.in_waiting > 7: # pylint: disable=no-member
240240
buffer = self.notification_source.read(8) # pylint: disable=no-member
@@ -261,7 +261,9 @@ def _update(self) -> Generator[Union[int, None], None, None]:
261261
del self._active_notifications[nid]
262262
yield None
263263

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]:
265267
"""Waits for new notifications and yields them. Returns on timeout, update, disconnect or
266268
clear."""
267269
start_time = time.monotonic()

0 commit comments

Comments
 (0)