Skip to content

Commit

Permalink
Merge pull request #43 from google/gbg/proxy-write-with-response
Browse files Browse the repository at this point in the history
support with_response on adapters
  • Loading branch information
barbibulle authored Oct 11, 2022
2 parents fbb46dd + 7fa2eb7 commit a916b7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions bumble/gatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ def write_encoded_value(self, connection, value):
async def read_decoded_value(self):
return self.decode_value(await self.wrapped_characteristic.read_value())

async def write_decoded_value(self, value):
return await self.wrapped_characteristic.write_value(self.encode_value(value))
async def write_decoded_value(self, value, with_response=False):
return await self.wrapped_characteristic.write_value(
self.encode_value(value),
with_response
)

def encode_value(self, value):
return value
Expand Down
4 changes: 2 additions & 2 deletions bumble/gatt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ async def send_request(self, request):
# Wait until we can send (only one pending command at a time for the connection)
response = None
async with self.request_semaphore:
assert(self.pending_request is None)
assert(self.pending_response is None)
assert self.pending_request is None
assert self.pending_response is None

# Create a future value to hold the eventual response
self.pending_response = asyncio.get_running_loop().create_future()
Expand Down
11 changes: 11 additions & 0 deletions tests/gatt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ def decode_value(self, value_bytes):
await async_barrier()
assert characteristic.value == bytes([124])

v = await cp.read_value()
assert v == 124
await cp.write_value(125, with_response=True)
await async_barrier()
assert characteristic.value == bytes([125])

cd = DelegatedCharacteristicAdapter(c, encode=lambda x: bytes([x // 2]))
await cd.write_value(100, with_response=True)
await async_barrier()
assert characteristic.value == bytes([50])

last_change = None

def on_change(value):
Expand Down

0 comments on commit a916b7a

Please sign in to comment.