Skip to content

Commit

Permalink
Merge pull request #295 from bluez-rs/pair
Browse files Browse the repository at this point in the history
Add method to pair with a device.
  • Loading branch information
qwandor authored Jan 6, 2025
2 parents eb39d2c + 1042172 commit bf8e162
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bluez-async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### New features

- Added `pair_with_timeout` and `cancel_pairing` to `BluetoothSession`.

## 0.8.0

### Breaking changes
Expand Down
20 changes: 19 additions & 1 deletion bluez-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,31 @@ impl BluetoothSession {
.unwrap_or(Err(BluetoothError::ServiceDiscoveryTimedOut))
}

/// Connect to the given Bluetooth device and initiate pairing, with the specified timeout.
pub async fn pair_with_timeout(
&self,
id: &DeviceId,
timeout: Duration,
) -> Result<(), BluetoothError> {
self.device(id, timeout).pair().await?;
self.await_service_discovery(id).await
}

/// Cancel a pairing operation with the given Bluetooth device.
pub async fn cancel_pairing(&self, id: &DeviceId) -> Result<(), BluetoothError> {
Ok(self
.device(id, DBUS_METHOD_CALL_TIMEOUT)
.cancel_pairing()
.await?)
}

/// Connect to the given Bluetooth device.
pub async fn connect(&self, id: &DeviceId) -> Result<(), BluetoothError> {
self.connect_with_timeout(id, DBUS_METHOD_CALL_TIMEOUT)
.await
}

/// Connect to the given Bluetooth device with specified timeout.
/// Connect to the given Bluetooth device with the specified timeout.
pub async fn connect_with_timeout(
&self,
id: &DeviceId,
Expand Down

0 comments on commit bf8e162

Please sign in to comment.