Skip to content

Commit 07f579c

Browse files
authored
Merge pull request #135 from tannewt/connect_to_address
Connect to an address directly
2 parents 9ae0e7f + 3d960fb commit 07f579c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

adafruit_ble/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BLEConnection:
3232
Represents a connection to a peer BLE device.
3333
It acts as a map from a `Service` type to a `Service` instance for the connection.
3434
35-
:param bleio_connection _bleio.Connection: the native `_bleio.Connection` object to wrap
35+
:param _bleio.Connection bleio_connection: the native `_bleio.Connection` object to wrap
3636
3737
"""
3838

@@ -227,15 +227,15 @@ def start_scan(
227227
:param float timeout: the scan timeout in seconds.
228228
If None, will scan until `stop_scan` is called.
229229
:param float interval: the interval (in seconds) between the start
230-
of two consecutive scan windows
231-
Must be in the range 0.0025 - 40.959375 seconds.
230+
of two consecutive scan windows
231+
Must be in the range 0.0025 - 40.959375 seconds.
232232
:param float window: the duration (in seconds) to scan a single BLE channel.
233-
window must be <= interval.
233+
window must be <= interval.
234234
:param int minimum_rssi: the minimum rssi of entries to return.
235235
:param bool active: request and retrieve scan responses for scannable advertisements.
236236
:return: If any ``advertisement_types`` are given,
237-
only Advertisements of those types are produced by the returned iterator.
238-
If none are given then `Advertisement` objects will be returned.
237+
only Advertisements of those types are produced by the returned iterator.
238+
If none are given then `Advertisement` objects will be returned.
239239
:rtype: iterable
240240
"""
241241
if not advertisement_types:
@@ -276,16 +276,18 @@ def stop_scan(self):
276276
once empty."""
277277
self._adapter.stop_scan()
278278

279-
def connect(self, advertisement, *, timeout=4.0):
279+
def connect(self, peer, *, timeout=4.0):
280280
"""
281281
Initiates a `BLEConnection` to the peer that advertised the given advertisement.
282282
283-
:param advertisement Advertisement: An `Advertisement` or a subclass of `Advertisement`
284-
:param timeout float: how long to wait for a connection
283+
:param peer: An `Advertisement`, a subclass of `Advertisement` or `_bleio.Address`
284+
:param float timeout: how long to wait for a connection
285285
:return: the connection to the peer
286286
:rtype: BLEConnection
287287
"""
288-
connection = self._adapter.connect(advertisement.address, timeout=timeout)
288+
if not isinstance(peer, _bleio.Address):
289+
peer = peer.address
290+
connection = self._adapter.connect(peer, timeout=timeout)
289291
self._connection_cache[connection] = BLEConnection(connection)
290292
return self._connection_cache[connection]
291293

examples/ble_uart_echo_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# SPDX-License-Identifier: MIT
33

44
"""
5-
Can be used with ble_uart_echo_client.py or with the UART page on the Adafruit Bluefruit Connect app.
6-
Receives characters from the UARTService and transmits them back.
5+
Can be used with ble_uart_echo_client.py or with the UART page on the
6+
Adafruit Bluefruit Connect app. Receives characters from the UARTService
7+
and transmits them back.
78
"""
89

910
from adafruit_ble import BLERadio

0 commit comments

Comments
 (0)