19
19
from adafruit_ble .uuid import VendorUUID
20
20
from adafruit_ble .services import Service
21
21
22
+ try :
23
+ import typing # pylint: disable=unused-import
24
+ from circuitpython_typing import WriteableBuffer , ReadableBuffer
25
+ except ImportError :
26
+ pass
27
+
22
28
__version__ = "0.0.0+auto.0"
23
29
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_MIDI.git"
24
30
@@ -30,7 +36,7 @@ class _MidiCharacteristic(ComplexCharacteristic):
30
36
31
37
uuid = VendorUUID ("7772E5DB-3868-4112-A1A9-F2669D106BF3" )
32
38
33
- def __init__ (self ):
39
+ def __init__ (self ) -> None :
34
40
super ().__init__ (
35
41
properties = Characteristic .WRITE_NO_RESPONSE
36
42
| Characteristic .READ
@@ -41,7 +47,7 @@ def __init__(self):
41
47
fixed_length = False ,
42
48
)
43
49
44
- def bind (self , service ) :
50
+ def bind (self , service : "MIDIService" ) -> _bleio . PacketBuffer :
45
51
"""Binds the characteristic to the given Service."""
46
52
bound_characteristic = super ().bind (service )
47
53
return _bleio .PacketBuffer (bound_characteristic , buffer_size = 4 )
@@ -60,7 +66,7 @@ class MIDIService(Service):
60
66
# so it complains about missing members.
61
67
# pylint: disable=no-member
62
68
63
- def __init__ (self , ** kwargs ):
69
+ def __init__ (self , ** kwargs ) -> None :
64
70
super ().__init__ (** kwargs )
65
71
# Defer creating _in_buffer until we're definitely connected.
66
72
self ._in_buffer = None
@@ -82,7 +88,7 @@ def __init__(self, **kwargs):
82
88
self ._in_index = 1
83
89
self ._last_data = True
84
90
85
- def readinto (self , buf , length ) :
91
+ def readinto (self , buf : WriteableBuffer , length : int ) -> int :
86
92
"""Reads up to ``length`` bytes into ``buf`` starting at index 0.
87
93
88
94
Returns the number of bytes written into ``buf``."""
@@ -115,13 +121,13 @@ def readinto(self, buf, length):
115
121
116
122
return i
117
123
118
- def read (self , length ) :
124
+ def read (self , length : int ) -> bytearray :
119
125
"""Reads up to ``length`` bytes and returns them."""
120
126
result = bytearray (length )
121
127
i = self .readinto (result , length )
122
128
return result [:i ]
123
129
124
- def write (self , buf , length ) :
130
+ def write (self , buf : ReadableBuffer , length : int ) -> None :
125
131
"""Writes ``length`` bytes out."""
126
132
# pylint: disable=too-many-branches
127
133
timestamp_ms = time .monotonic_ns () // 1000000
0 commit comments