From 10421727c50e4ea669b94a22dd82efe547e3b3e5 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Mon, 6 Jan 2025 17:46:07 +0000 Subject: [PATCH] Add method to pair with a device. --- bluez-async/CHANGELOG.md | 6 ++++++ bluez-async/src/lib.rs | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bluez-async/CHANGELOG.md b/bluez-async/CHANGELOG.md index 096012ab..070e54b1 100644 --- a/bluez-async/CHANGELOG.md +++ b/bluez-async/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### New features + +- Added `pair_with_timeout` and `cancel_pairing` to `BluetoothSession`. + ## 0.8.0 ### Breaking changes diff --git a/bluez-async/src/lib.rs b/bluez-async/src/lib.rs index eb48d8f3..bb551d4c 100644 --- a/bluez-async/src/lib.rs +++ b/bluez-async/src/lib.rs @@ -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,