Example #1
0
    async def discover(cls,
                       timeout: float = 5.0,
                       adapter: Optional[str] = None,
                       **kwargs: object) -> AsyncGenerator[BLEDevice, None]:
        """
        Generator to discover RadonEye RD200 devices
        :return: BLEDevice objects
        """

        device_queue: asyncio.Queue[BLEDevice] = asyncio.Queue()

        def detection_callback(d: BLEDevice,
                               ad: Optional[AdvertisementData]) -> None:
            if "uuids" in d.metadata:
                uuids = d.metadata["uuids"]
            elif ad is not None:
                uuids = ad.service_uuids
            else:
                return
            if RD200.LBS_UUID_SERVICE in uuids:
                device_queue.put_nowait(d)

        # Can't pass adapter=None to BleakScanner
        if adapter is not None:
            kwargs.update(adapter=adapter)

        async with bleak.BleakScanner(detection_callback=detection_callback,
                                      **kwargs) as scanner:
            for device in await scanner.get_discovered_devices():
                detection_callback(device, None)
            start_time = time.time()
            while True:
                yield await asyncio.wait_for(
                    device_queue.get(), timeout - (time.time() - start_time))
Example #2
0
async def scan_for_device(device_name, *, log=print):
    device_was_found_future = asyncio.Future()

    def any_device_discovered_callback(device, advertisement_data):
        if device.name == device_name:
            device_was_found_future.set_result(device)
            log(f"FOUND device: {device.name}, rssi is {device.rssi} address is {device.address}"
                )
        elif device.name != "Unknown":
            log(f"seeing device: {device.name}")

    async with bleak.BleakScanner() as scanner:
        scanner.register_detection_callback(any_device_discovered_callback)
        log(f"looking for {device_name}")
        return await device_was_found_future
 async def async_run(listener):
     scanner = bleak.BleakScanner()
     scanner.register_detection_callback(
         lambda e: listener.ble_event(e))
     await scanner.start()
Example #4
0
 def __init__(self):
     self._scanner = bleak.BleakScanner()
     self._near_addresses = []
     self._connected = []
Example #5
0
 def __init__(self):
     self._scanner = sync.methods(bleak.BleakScanner())
     self._near_addresses = []
     self._connected = []