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

drop BLEDeviceCoreBluetooth #977

Merged
merged 2 commits into from
Sep 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Fixed
* Fixed wrong error message for BlueZ "Operation failed with ATT error". Merged #975.
* Fixed possible ``AttributeError`` when enabling notifications for battery service in BlueZ backend. Merged #976.

Removed
-------
- Removed ``BLEDeviceCoreBluetooth`` type from CoreBluetooth backend. Merged #977.

`0.16.0`_ (2022-08-31)
======================

Expand Down
31 changes: 10 additions & 21 deletions bleak/backends/corebluetooth/CentralManagerDelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
)
from libdispatch import dispatch_queue_create, DISPATCH_QUEUE_SERIAL

from bleak.backends.corebluetooth.device import BLEDeviceCoreBluetooth
from bleak.exc import BleakError
from ...exc import BleakError

logger = logging.getLogger(__name__)
CBCentralManagerDelegate = objc.protocolNamed("CBCentralManagerDelegate")
Expand All @@ -62,7 +61,7 @@ def init(self) -> Optional["CentralManagerDelegate"]:
self.event_loop = asyncio.get_running_loop()
self._connect_futures: Dict[NSUUID, asyncio.Future] = {}

self.devices: Dict[str, BLEDeviceCoreBluetooth] = {}
self.last_rssi: Dict[str, int] = {}

self.callbacks: Dict[
int, Callable[[CBPeripheral, Dict[str, Any], int], None]
Expand Down Expand Up @@ -107,7 +106,7 @@ def __del__(self):
@objc.python_method
async def start_scan(self, service_uuids) -> None:
# remove old
self.devices = {}
self.last_rssi.clear()

service_uuids = (
NSArray.alloc().initWithArray_(
Expand Down Expand Up @@ -252,29 +251,19 @@ def did_discover_peripheral(

uuid_string = peripheral.identifier().UUIDString()

if uuid_string in self.devices:
device = self.devices[uuid_string]
# It could be the device did not have a name previously but now it does.
if peripheral.name():
device.name = peripheral.name()
else:
address = uuid_string
name = peripheral.name() or None
details = peripheral
device = BLEDeviceCoreBluetooth(address, name, details, delegate=self)
self.devices[uuid_string] = device

device._update(advertisementData)
device._update_rssi(RSSI)
self.last_rssi[uuid_string] = RSSI

for callback in self.callbacks.values():
if callback:
callback(peripheral, advertisementData, RSSI)

logger.debug(
"Discovered device {}: {} @ RSSI: {} (kCBAdvData {}) and Central: {}".format(
uuid_string, device.name, RSSI, advertisementData.keys(), central
)
"Discovered device %s: %s @ RSSI: %d (kCBAdvData %r) and Central: %r",
uuid_string,
peripheral.name(),
RSSI,
advertisementData.keys(),
central,
)

def centralManager_didDiscoverPeripheral_advertisementData_RSSI_(
Expand Down
64 changes: 0 additions & 64 deletions bleak/backends/corebluetooth/device.py

This file was deleted.

2 changes: 1 addition & 1 deletion bleak/backends/corebluetooth/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def discovered_devices(self) -> List[BLEDevice]:
address = peripheral.identifier().UUIDString()
name = peripheral.name() or "Unknown"
details = peripheral
rssi = self._manager.devices[address].rssi
rssi = self._manager.last_rssi[address]

advertisementData = self._identifiers[peripheral.identifier()]
manufacturer_binary_data = advertisementData.get(
Expand Down