Skip to content

Commit bf8e162

Browse files
authored
Merge pull request #295 from bluez-rs/pair
Add method to pair with a device.
2 parents eb39d2c + 1042172 commit bf8e162

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

bluez-async/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### New features
6+
7+
- Added `pair_with_timeout` and `cancel_pairing` to `BluetoothSession`.
8+
39
## 0.8.0
410

511
### Breaking changes

bluez-async/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,31 @@ impl BluetoothSession {
707707
.unwrap_or(Err(BluetoothError::ServiceDiscoveryTimedOut))
708708
}
709709

710+
/// Connect to the given Bluetooth device and initiate pairing, with the specified timeout.
711+
pub async fn pair_with_timeout(
712+
&self,
713+
id: &DeviceId,
714+
timeout: Duration,
715+
) -> Result<(), BluetoothError> {
716+
self.device(id, timeout).pair().await?;
717+
self.await_service_discovery(id).await
718+
}
719+
720+
/// Cancel a pairing operation with the given Bluetooth device.
721+
pub async fn cancel_pairing(&self, id: &DeviceId) -> Result<(), BluetoothError> {
722+
Ok(self
723+
.device(id, DBUS_METHOD_CALL_TIMEOUT)
724+
.cancel_pairing()
725+
.await?)
726+
}
727+
710728
/// Connect to the given Bluetooth device.
711729
pub async fn connect(&self, id: &DeviceId) -> Result<(), BluetoothError> {
712730
self.connect_with_timeout(id, DBUS_METHOD_CALL_TIMEOUT)
713731
.await
714732
}
715733

716-
/// Connect to the given Bluetooth device with specified timeout.
734+
/// Connect to the given Bluetooth device with the specified timeout.
717735
pub async fn connect_with_timeout(
718736
&self,
719737
id: &DeviceId,

0 commit comments

Comments
 (0)