diff --git a/bluez-async/src/lib.rs b/bluez-async/src/lib.rs index eb48d8f3..89a5761c 100644 --- a/bluez-async/src/lib.rs +++ b/bluez-async/src/lib.rs @@ -723,6 +723,33 @@ impl BluetoothSession { self.await_service_discovery(id).await } + /// Connect to a device with the given address on the specified adapter. + /// + /// The BlueZ documentation says that this method is experimental. + pub async fn connect_device( + &self, + adapter_id: &AdapterId, + address: MacAddress, + address_type: Option, + ) -> Result { + let mut properties: PropMap = HashMap::new(); + properties.insert( + "Address".to_string(), + Variant(Box::new(address.to_string())), + ); + if let Some(address_type) = address_type { + properties.insert( + "AddressType".to_string(), + Variant(Box::new(address_type.to_string())), + ); + } + + let adapter = self.adapter(adapter_id); + let id = adapter.connect_device(properties).await?; + self.await_service_discovery(id).await?; + Ok(id) + } + /// Disconnect from the given Bluetooth device. pub async fn disconnect(&self, id: &DeviceId) -> Result<(), BluetoothError> { Ok(self diff --git a/bluez-generated/src/adapter1.rs b/bluez-generated/src/adapter1.rs index 1003fbf8..d13aaee6 100644 --- a/bluez-generated/src/adapter1.rs +++ b/bluez-generated/src/adapter1.rs @@ -9,6 +9,7 @@ pub trait OrgBluezAdapter1 { fn stop_discovery(&self) -> nonblock::MethodReply<()>; fn remove_device(&self, device: dbus::Path) -> nonblock::MethodReply<()>; fn get_discovery_filters(&self) -> nonblock::MethodReply>; + fn connect_device(&self, properties: arg::PropMap) -> nonblock::MethodReply>; fn address(&self) -> nonblock::MethodReply; fn address_type(&self) -> nonblock::MethodReply; fn name(&self) -> nonblock::MethodReply; @@ -134,6 +135,11 @@ impl<'a, T: nonblock::NonblockReply, C: ::std::ops::Deref> OrgBluezA .and_then(|r: (Vec,)| Ok(r.0)) } + fn connect_device(&self, properties: arg::PropMap) -> nonblock::MethodReply> { + self.method_call("org.bluez.Adapter1", "ConnectDevice", (properties,)) + .and_then(|r: (Vec,)| Ok(r.0)) + } + fn address(&self) -> nonblock::MethodReply { ::get( &self,