# Buggy code
async def get_discovered_devices(self) -> List[BLEDevice]:
    found = []
    peripherals = self._manager.central_manager.retrievePeripheralsWithIdentifiers_(
        self._identifiers.keys(),
    )

    for i, peripheral in enumerate(peripherals):
        address = peripheral.identifier().UUIDString()
        name = peripheral.name() or "Unknown"
        details = peripheral

        advertisementData = self._identifiers[peripheral.identifier()]
        manufacturer_binary_data = advertisementData.get("kCBAdvDataManufacturerData")
        manufacturer_data = {}
        if manufacturer_binary_data:
            manufacturer_id = int.from_bytes(
                manufacturer_binary_data[0:2], byteorder="little"
            )
            manufacturer_value = bytes(manufacturer_binary_data[2:])
            manufacturer_data = {manufacturer_id: manufacturer_value}

        uuids = [
            cb_uuid_to_str(u)
            for u in advertisementData.get("kCBAdvDataServiceUUIDs", [])
        ]

        found.append(
            BLEDevice(
                address,
                name,
                details,
                uuids=uuids,
                manufacturer_data=manufacturer_data,
                delegate=self._manager.central_manager.delegate(),
            )
        )

    return found


# Traceback (objc.error)
2020-10-12 22:16:31.801 Python[3820:332546] *** Assertion failure in -[CBCentralManager retrievePeripheralsWithIdentifiers:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreBluetooth/CoreBluetooth-102.23/CBCentralManager.m:203
Traceback (most recent call last):
File "bleak_test3.py", line 52, in <module>
loop.run_until_complete(run())
File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "bleak_test3.py", line 12, in run
await client.connect()
File "/Users/GirlOne/dev/formid_hfs/venv/lib/python3.8/site-packages/bleak/backends/corebluetooth/client.py", line 76, in connect
device = await BleakScannerCoreBluetooth.find_device_by_address(
File "/Users/GirlOne/dev/formid_hfs/venv/lib/python3.8/site-packages/bleak/backends/corebluetooth/scanner.py", line 157, in find_device_by_address
return await scanner._find_device_by_address(
File "/Users/GirlOne/dev/formid_hfs/venv/lib/python3.8/site-packages/bleak/backends/scanner.py", line 107, in _find_device_by_address
for d in await self.get_discovered_devices()
File "/Users/GirlOne/dev/formid_hfs/venv/lib/python3.8/site-packages/bleak/backends/corebluetooth/scanner.py", line 82, in get_discovered_devices
peripherals = self._manager.central_manager.retrievePeripheralsWithIdentifiers_(
objc.error: NSInternalInconsistencyException - Invalid parameter not satisfying: [identifiers isKindOfClass:[NSArray class]]

# Fixed code
async def get_discovered_devices(self) -> List[BLEDevice]:
    found = []
    peripherals = self._manager.central_manager.retrievePeripheralsWithIdentifiers_(
        NSArray(self._identifiers.keys()),
    )

    for i, peripheral in enumerate(peripherals):
        address = peripheral.identifier().UUIDString()
        name = peripheral.name() or "Unknown"
        details = peripheral

        advertisementData = self._identifiers[peripheral.identifier()]
        manufacturer_binary_data = advertisementData.get("kCBAdvDataManufacturerData")
        manufacturer_data = {}
        if manufacturer_binary_data:
            manufacturer_id = int.from_bytes(
                manufacturer_binary_data[0:2], byteorder="little"
            )
            manufacturer_value = bytes(manufacturer_binary_data[2:])
            manufacturer_data = {manufacturer_id: manufacturer_value}

        uuids = [
            cb_uuid_to_str(u)
            for u in advertisementData.get("kCBAdvDataServiceUUIDs", [])
        ]

        found.append(
            BLEDevice(
                address,
                name,
                details,
                uuids=uuids,
                manufacturer_data=manufacturer_data,
                delegate=self._manager.central_manager.delegate(),
            )
        )

    return found