From 70711a6804387406844c682297786de795a63ef3 Mon Sep 17 00:00:00 2001 From: Etienne Posthumus Date: Wed, 5 May 2021 16:56:22 +0200 Subject: [PATCH 1/2] During init() support raising a "BLE is unsupported" For some older devices the bluetooth stack does not support BLE. The error message "Bluetooth device is turned off" can then be confusing, if on that device bluetooth is actually switched on (and working) but the actual problem is that BLE is not supported. --- bleak/backends/corebluetooth/CentralManagerDelegate.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bleak/backends/corebluetooth/CentralManagerDelegate.py b/bleak/backends/corebluetooth/CentralManagerDelegate.py index 836fe60d..8b94f07d 100644 --- a/bleak/backends/corebluetooth/CentralManagerDelegate.py +++ b/bleak/backends/corebluetooth/CentralManagerDelegate.py @@ -89,6 +89,10 @@ def init(self): # It doesn't take long for the callback to occur, so we should be able # to do a blocking wait here without anyone complaining. self._did_update_state_event.wait(1) + + if self.central_manager.state() == CBManagerStateUnsupported: + raise BleakError("BLE is unsupported") + if self.central_manager.state() != CBManagerStatePoweredOn: raise BleakError("Bluetooth device is turned off") From 25006d5e902de974b7866368475b0f5920f48c35 Mon Sep 17 00:00:00 2001 From: Etienne Posthumus Date: Tue, 11 May 2021 23:49:32 +0200 Subject: [PATCH 2/2] Remove superflous spaces --- bleak/backends/corebluetooth/CentralManagerDelegate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bleak/backends/corebluetooth/CentralManagerDelegate.py b/bleak/backends/corebluetooth/CentralManagerDelegate.py index 8b94f07d..37114786 100644 --- a/bleak/backends/corebluetooth/CentralManagerDelegate.py +++ b/bleak/backends/corebluetooth/CentralManagerDelegate.py @@ -89,10 +89,10 @@ def init(self): # It doesn't take long for the callback to occur, so we should be able # to do a blocking wait here without anyone complaining. self._did_update_state_event.wait(1) - + if self.central_manager.state() == CBManagerStateUnsupported: raise BleakError("BLE is unsupported") - + if self.central_manager.state() != CBManagerStatePoweredOn: raise BleakError("Bluetooth device is turned off")