Skip to content

Commit

Permalink
deprecate discover() function
Browse files Browse the repository at this point in the history
The discover() function was removed from the docs and was supposed to
be deprecated some time ago, but it didn't get a proper warning and
was still used in some examples.

This removes it from the examples and adds a warning so that it can
eventually be removed.
  • Loading branch information
dlech committed Sep 12, 2022
1 parent 0ee98ff commit 825df5d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Changed
* The BlueZ D-Bus backend now uses ``dbus-fast`` instead of ``dbus-next`` which significantly improves performance.
* The BlueZ D-Bus backend will not avoid trying to connect to devices that are already connected. Fixes #992.
* Updated logging to lazy version and replaced format by f-string for BleakClientWinRT
* Added deprecation warning to ``discover()`` method.

Fixed
-----
Expand Down
16 changes: 14 additions & 2 deletions bleak/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import platform
import asyncio
from warnings import warn

from bleak.__version__ import __version__ # noqa: F401
from bleak.exc import BleakError
Expand Down Expand Up @@ -80,9 +81,20 @@
else:
raise BleakError(f"Unsupported platform: {platform.system()}")


# for backward compatibility
if not _on_rtd:
discover = BleakScanner.discover
def discover():
"""
.. deprecated:: 0.17.0
This method will be removed in a future version of Bleak.
Use :meth:`BleakScanner.discover` instead.
"""
warn(
"The discover function will removed in a future version, use BleakScanner.discover instead.",
FutureWarning,
stacklevel=2,
)
return BleakScanner.discover()


def cli():
Expand Down
4 changes: 2 additions & 2 deletions examples/disconnect_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import asyncio

from bleak import BleakClient, discover
from bleak import BleakScanner, BleakClient


async def main():
devs = await discover()
devs = await BleakScanner.discover()
if not devs:
print("No devices found, try again later.")
return
Expand Down
5 changes: 3 additions & 2 deletions examples/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"""

import asyncio
from bleak import discover

from bleak import BleakScanner


async def main():
devices = await discover()
devices = await BleakScanner.discover()
for d in devices:
print(d)

Expand Down

0 comments on commit 825df5d

Please sign in to comment.