Skip to content

Commit 2dae081

Browse files
committed
Documentation commit.
Updated documentation about scanning filters. Added scanning filters to .NET discover method. Updated CHANGLOG.
1 parent d6f4a6f commit 2dae081

File tree

11 files changed

+56
-17
lines changed

11 files changed

+56
-17
lines changed

CHANGELOG.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Added
1818
* Two devices example file to use for e.g. debugging.
1919
* Detection/discovery callbacks in Core Bluetooth backend ```Scanner`` implemented.
2020
* Characteristic handle printout in ``service_explorer.py``.
21+
* Added scanning filters to .NET backend's ``discover`` method.
2122

2223
Changed
2324
~~~~~~~
@@ -36,15 +37,10 @@ Changed
3637
* Renamed ``HISTORY.rst`` to ``CHANGELOG.rst`` and adopted
3738
the `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_ format.
3839
* Python 3.5 support from macOS is officially removed since pyobjc>6 requires 3.6+
39-
* Pin pyobjc to version 6.2. (PR #194)
40-
* Pin pyobjc-framework-corebluetooth to version 6.2.
40+
* Pin ``pyobjc`` dependencies to use at least version 6.2. (PR #194)
4141
* Pin development requirement on `bump2version` to version 1.0.0
4242
* Added ``.pyup.yml`` for Pyup
4343
* Using CBManagerState constants from pyobj instead of integers.
44-
* Improved handling of the txdbus connection to avoid hanging of disconnection
45-
clients in BlueZ backend. Fixes #216, #219 & #221.
46-
* #150 hints at the device path not being possible to create as is done in the `get_device_object_path` method.
47-
Now, we try to get it from BlueZ first. Otherwise, use the old fallback.
4844

4945
Removed
5046
~~~~~~~
@@ -54,13 +50,17 @@ Removed
5450
* Removed the ``bleak.backends.bluez.utils.get_gatt_service_path`` method. It is not used by
5551
bleak and possibly generates errors.
5652

57-
5853
Fixed
5954
~~~~~
6055

56+
* Improved handling of the txdbus connection to avoid hanging of disconnection
57+
clients in BlueZ backend. Fixes #216, #219 & #221.
58+
* #150 hints at the device path not being possible to create as is done in the `get_device_object_path` method.
59+
Now, we try to get it from BlueZ first. Otherwise, use the old fallback.
6160
* Minor documentation errors corrected.
6261
* ``CBManagerStatePoweredOn`` is now properly handled in Core Bluetooth.
6362
* Device enumeration in ``discover``and ``Scanner`` corrected. Fixes #211
63+
* Updated documentation about scanning filters.
6464

6565
`0.6.4`_ (2020-05-20)
6666
---------------------

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
MIT License
33

4-
Copyright (c) 2019, Henrik Blidh
4+
Copyright (c) 2020, Henrik Blidh
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
77

bleak/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# -*- coding: utf-8 -*-
22

3-
__version__ = "0.6.5a8"
3+
__version__ = "0.6.5a9"

bleak/backends/dotnet/discovery.py

+14
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,22 @@ async def discover(
3636
loop (Event Loop): The event loop to use.
3737
3838
Keyword Args:
39+
SignalStrengthFilter (Windows.Devices.Bluetooth.BluetoothSignalStrengthFilter): A
40+
BluetoothSignalStrengthFilter object used for configuration of Bluetooth
41+
LE advertisement filtering that uses signal strength-based filtering.
42+
AdvertisementFilter (Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementFilter): A
43+
BluetoothLEAdvertisementFilter object used for configuration of Bluetooth LE
44+
advertisement filtering that uses payload section-based filtering.
3945
string_output (bool): If set to false, ``discover`` returns .NET
4046
device objects instead.
4147
4248
Returns:
4349
List of strings or objects found.
4450
4551
"""
52+
signal_strength_filter = kwargs.get("SignalStrengthFilter", None)
53+
advertisement_filter = kwargs.get("AdvertisementFilter", None)
54+
4655
loop = loop if loop else asyncio.get_event_loop()
4756

4857
watcher = BluetoothLEAdvertisementWatcher()
@@ -85,6 +94,11 @@ def AdvertisementWatcher_Stopped(sender, e):
8594

8695
watcher.ScanningMode = BluetoothLEScanningMode.Active
8796

97+
if signal_strength_filter is not None:
98+
watcher.SignalStrengthFilter = signal_strength_filter
99+
if advertisement_filter is not None:
100+
watcher.AdvertisementFilter = advertisement_filter
101+
88102
# Watcher works outside of the Python process.
89103
watcher.Start()
90104
await asyncio.sleep(timeout, loop=loop)

bleak/backends/scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class BaseBleakScanner(abc.ABC):
10-
"""Interface for Bleak Bluetooth LE Scanners
10+
"""Interface for Bleak Bluetooth LE Scanners.
1111
1212
Args:
1313
loop (Event Loop): The event loop to use.

docs/api.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Connection Client Interface
88
:members:
99

1010
Scanning Client Interface
11-
---------------------------
11+
-------------------------
1212

13-
.. automodule:: bleak.backends.scanning
13+
.. automodule:: bleak.backends.scanner
1414
:members:
1515

1616
Interface for BLE devices

docs/backends/windows.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ The Windows backend implements a ``BleakClient`` in the module ``bleak.backends.
99
method in the ``bleak.backends.dotnet.discovery`` module. There are also backend-specific implementations of the
1010
``BleakGATTService``, ``BleakGATTCharacteristic`` and ``BleakGATTDescriptor`` classes.
1111

12-
FInally, some .NET/``asyncio``-connectivity methods are available in the ``bleak.backends.dotnet.utils`` module.
12+
Finally, some .NET/``asyncio``-connectivity methods are available in the ``bleak.backends.dotnet.utils`` module.
1313

1414
Specific features for the Windows backend
1515
-----------------------------------------
1616

1717
Client
1818
~~~~~~
1919
- The constructor keyword ``address_type`` which can have the values ``"public"`` or ``"random"``. This value
20-
makes sure that the connect
20+
makes sure that the connection is made in a fashion that suits the peripheral.
2121

docs/history.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.. include:: ../HISTORY.rst
1+
.. include:: ../CHANGELOG.rst

docs/scanning.rst

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and ``rssi`` attributes, as well as a ``metadata`` attribute, a dict with keys `
3131
which potentially contains a list of all service UUIDs on the device and a binary string of data from
3232
the manufacturer of the device respectively.
3333

34+
3435
BleakScanner
3536
------------
3637

@@ -95,3 +96,19 @@ or separately, calling ``start`` and ``stop`` methods on the scanner manually:
9596
In the manual mode, it is possible to add an own callback that you want to call upon each
9697
scanner detection, as can be seen above. There is also possibilities of adding scanning filters,
9798
but these differ so widely between implementations, so these details are recorded there instead.
99+
100+
Scanning Filters
101+
----------------
102+
103+
There are some scanning filters that can be applied, that will reduce your scanning
104+
results prior to them getting to bleak. These are pretty quite backend specific, but
105+
they are generally used like this:
106+
107+
- On the `discover` method, send in keyword arguments according to what is
108+
described in the docstring of the method.
109+
- On the backend's `BleakScanner` implementation, either send in keyword arguments
110+
according to what is described in the docstring of the class or use the
111+
``set_scanning_filter`` method to set them after the instance has been created.
112+
113+
Scanning filters are currently implemented in Windows and BlueZ backends, but not yet
114+
in the macOS backend.

docs/usage.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
Usage
33
=====
44

5+
.. note::
6+
7+
A Bluetooth peripheral may have several characteristics with the same UUID, so
8+
the means of specifying characteristics by UUID or string representation of it
9+
might not always work in bleak version > 0.7.0. One can now also use the characteristic's
10+
handle or even the ``BleakGATTCharacteristic`` object itself in
11+
``read_gatt_char``, ``write_gatt_char``, ``start_notify``, and ``stop_notify``.
12+
513

614
One can use the ``BleakClient`` to connect to a Bluetooth device and read its model number
715
via the asyncronous context manager like this:
@@ -46,7 +54,7 @@ or one can do it without the context manager like this:
4654
loop = asyncio.get_event_loop()
4755
loop.run_until_complete(run(address, loop))
4856
49-
Try to make sure you always get to call the disconnect method for a client before discarding it;
57+
Make sure you always get to call the disconnect method for a client before discarding it;
5058
the Bluetooth stack on the OS might need to be cleared of residual data which is cached in the
5159
``BleakClient``.
5260

examples/sensortag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def run(address, loop, debug=False):
104104
# h.setLevel(logging.DEBUG)
105105
# l.addHandler(h)
106106

107-
async with BleakClient(address, loop=loop) as client:
107+
async with BleakClient(address, timeout=1.0, loop=loop) as client:
108108
x = await client.is_connected()
109109
logger.info("Connected: {0}".format(x))
110110

0 commit comments

Comments
 (0)