File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -524,7 +524,12 @@ async def pair(
524
524
BleakPairingFailedError:
525
525
if pairing failed (rejected, wrong pin, etc.)
526
526
"""
527
- return await self ._backend .pair (callbacks , ** kwargs )
527
+ if await self ._backend .pair (callbacks , ** kwargs ):
528
+ # If services were already discovered during connection procedure, this will return cached
529
+ # services anyway. If `skip_service_discovery=True` was used, this will perform the discovery.
530
+ await self ._backend .get_services ()
531
+ return True
532
+ return False
528
533
529
534
async def unpair (self ) -> bool :
530
535
"""
Original file line number Diff line number Diff line change @@ -78,10 +78,19 @@ async def main(addr: str, unpair: bool) -> None:
78
78
79
79
print ("pairing..." )
80
80
81
- async with BleakClient (device ) as client , AgentCallbacks () as callbacks :
81
+ async with (
82
+ BleakClient (device ) as client ,
83
+ # If the peripheral device sends Slave Security Request immediately upon establishing connection,
84
+ # the central device shall respond with the pairing request - usually before starting/finishing
85
+ # service discovery, that is before connect() method normally returns. In such cases the pairing
86
+ # process usually fails with "Pairing not supported" error - as a workaround,
87
+ # BleakClient(device, skip_service_discovery=True) as client,
88
+ # can be used, which will execute service discovery only after pairing.
89
+ AgentCallbacks () as callbacks ,
90
+ ):
82
91
try :
83
92
await client .pair (callbacks )
84
- print ("pairing successful" )
93
+ print (f "pairing successful, { len ( client . services . services ) } services " )
85
94
except BleakPairingCancelledError :
86
95
print ("paring was canceled" )
87
96
except BleakPairingFailedError :
You can’t perform that action at this time.
0 commit comments