Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backends/corebluetooth: better error message for unauthorized #1033

Merged
merged 1 commit into from Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -13,6 +13,7 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
Added
-----
* Added support for Python 3.11.
* Added better error message for Bluetooth not authorized on macOS.

`0.18.1`_ (2022-09-25)
======================
Expand Down
3 changes: 3 additions & 0 deletions bleak/backends/corebluetooth/CentralManagerDelegate.py
Expand Up @@ -84,6 +84,9 @@ def init(self) -> Optional["CentralManagerDelegate"]:
if self.central_manager.state() == CBManagerStateUnsupported:
raise BleakError("BLE is unsupported")

if self.central_manager.state() == CBManagerStateUnauthorized:
raise BleakError("BLE is not authorized - check macOS privacy settings")

if self.central_manager.state() != CBManagerStatePoweredOn:
raise BleakError("Bluetooth device is turned off")

Expand Down
5 changes: 5 additions & 0 deletions docs/troubleshooting.rst
Expand Up @@ -43,6 +43,11 @@ the *Privacy* settings in the macOS *System Preferences*.

.. image:: images/macos-privacy-bluetooth.png

If the app is already in the list but the checkbox for Bluetooth is disabled,
you will get the a ``BleakError``: "BLE is not authorized - check macOS privacy settings".
instead of crashing with ``SIGABRT``, in which case you need to check the box
to allow Bluetooth for the app that is running Python.


No devices found when scanning on macOS 12
==========================================
Expand Down