Skip to content

Commit

Permalink
During init() support raising a "BLE is unsupported" (#533)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
epoz authored May 11, 2021
1 parent d8fba81 commit 0f74fc0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bleak/backends/corebluetooth/CentralManagerDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 0f74fc0

Please sign in to comment.