Skip to content

Commit 765f14b

Browse files
committed
aioble/server.py: Fix registration for descriptors.
This allows a server to register descriptors, which was previously not fully implemented. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
1 parent 64e752c commit 765f14b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

micropython/bluetooth/aioble/aioble/server.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ def _register(self, value_handle):
8383
self.write(self._initial)
8484
self._initial = None
8585

86-
# Generate tuple for gatts_register_services.
87-
def _tuple(self):
88-
return (self.uuid, self.flags)
89-
9086
# Read value from local db.
9187
def read(self):
9288
if self._value_handle is None:
@@ -105,8 +101,9 @@ def write(self, data, send_update=False):
105101
# the write, or a tuple of (connection, value) if capture is enabled for
106102
# this characteristics.
107103
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
110107

111108
# If the queue is empty, then we need to wait. However, if the queue
112109
# has a single item, we also need to do a no-op wait in order to
@@ -200,6 +197,14 @@ def __init__(
200197
self._value_handle = None
201198
self._initial = initial
202199

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+
203208
def notify(self, connection, data=None):
204209
if not (self.flags & _FLAG_NOTIFY):
205210
raise ValueError("Not supported")
@@ -257,15 +262,19 @@ def __init__(self, characteristic, uuid, read=False, write=False, initial=None):
257262
if read:
258263
flags |= _FLAG_DESC_READ
259264
if write:
260-
self._write_connection = None
261265
self._write_event = asyncio.ThreadSafeFlag()
266+
self._write_queue = deque((), 1)
262267
flags |= _FLAG_DESC_WRITE
263268

264269
self.uuid = uuid
265270
self.flags = flags
266271
self._value_handle = None
267272
self._initial = initial
268273

274+
# Generate tuple for gatts_register_services.
275+
def _tuple(self):
276+
return (self.uuid, self.flags)
277+
269278

270279
# Turn the Service/Characteristic/Descriptor classes into a registration tuple
271280
# and then extract their value handles.

0 commit comments

Comments
 (0)