From 7d519ddee7dc9768ac55dd6a7cbfd2595b2db906 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 26 Sep 2022 15:01:40 -0500 Subject: [PATCH] backends/corebluetooth: better error message for unauthorized If Bleak is run in a terminal app on macOS that has the permission for Bluetooth disabled, the CentralManager state will return unauthorized. Previously, this raised the same error as when Bluetooth is not powered which is misleading. This adds a new error message for the unauthorized case. Issue: https://github.com/hbldh/bleak/discussions/1016 --- CHANGELOG.rst | 1 + bleak/backends/corebluetooth/CentralManagerDelegate.py | 3 +++ docs/troubleshooting.rst | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 17654028..503253f9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ and this project adheres to `Semantic Versioning 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") diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index 6fb71296..0b139522 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -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 ==========================================