@@ -83,10 +83,6 @@ def _register(self, value_handle):
83
83
self .write (self ._initial )
84
84
self ._initial = None
85
85
86
- # Generate tuple for gatts_register_services.
87
- def _tuple (self ):
88
- return (self .uuid , self .flags )
89
-
90
86
# Read value from local db.
91
87
def read (self ):
92
88
if self ._value_handle is None :
@@ -105,8 +101,9 @@ def write(self, data, send_update=False):
105
101
# the write, or a tuple of (connection, value) if capture is enabled for
106
102
# this characteristics.
107
103
async def written (self , timeout_ms = None ):
108
- if not self ._write_event :
109
- raise ValueError ()
104
+ if not hasattr (self , "_write_event" ):
105
+ # Not a writable characteristic.
106
+ return
110
107
111
108
# If the queue is empty, then we need to wait. However, if the queue
112
109
# has a single item, we also need to do a no-op wait in order to
@@ -200,6 +197,14 @@ def __init__(
200
197
self ._value_handle = None
201
198
self ._initial = initial
202
199
200
+ # Generate tuple for gatts_register_services.
201
+ def _tuple (self ):
202
+ if self .descriptors :
203
+ return (self .uuid , self .flags , tuple (d ._tuple () for d in self .descriptors ))
204
+ else :
205
+ # Workaround: v1.19 and below can't handle an empty descriptor tuple.
206
+ return (self .uuid , self .flags )
207
+
203
208
def notify (self , connection , data = None ):
204
209
if not (self .flags & _FLAG_NOTIFY ):
205
210
raise ValueError ("Not supported" )
@@ -257,15 +262,19 @@ def __init__(self, characteristic, uuid, read=False, write=False, initial=None):
257
262
if read :
258
263
flags |= _FLAG_DESC_READ
259
264
if write :
260
- self ._write_connection = None
261
265
self ._write_event = asyncio .ThreadSafeFlag ()
266
+ self ._write_queue = deque ((), 1 )
262
267
flags |= _FLAG_DESC_WRITE
263
268
264
269
self .uuid = uuid
265
270
self .flags = flags
266
271
self ._value_handle = None
267
272
self ._initial = initial
268
273
274
+ # Generate tuple for gatts_register_services.
275
+ def _tuple (self ):
276
+ return (self .uuid , self .flags )
277
+
269
278
270
279
# Turn the Service/Characteristic/Descriptor classes into a registration tuple
271
280
# and then extract their value handles.
0 commit comments