aioble: Add timeout to device.exchange_mtu.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/523/head
Andrew Leech 2021-08-17 11:17:29 +10:00 zatwierdzone przez Jim Mussared
rodzic c3f4779002
commit 09f0e47386
1 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -262,7 +262,7 @@ class DeviceConnection:
def timeout(self, timeout_ms):
return DeviceTimeout(self, timeout_ms)
async def exchange_mtu(self, mtu=None):
async def exchange_mtu(self, mtu=None, timeout_ms=1000):
if not self.is_connected():
raise ValueError("Not connected")
@ -271,7 +271,8 @@ class DeviceConnection:
self._mtu_event = self._mtu_event or asyncio.ThreadSafeFlag()
ble.gattc_exchange_mtu(self._conn_handle)
await self._mtu_event.wait()
with self.timeout(timeout_ms):
await self._mtu_event.wait()
return self.mtu
# Wait for a connection on an L2CAP connection-oriented-channel.