[WIP] Basic scanner output test
This commit is contained in:
parent
f4be2c9ff4
commit
8bd65f2015
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from ..tools.ble import scanner
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
def scan():
|
def scan():
|
||||||
pass
|
scanner.run()
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
|
import asyncio
|
||||||
from bleak import BleakScanner
|
from bleak import BleakScanner
|
||||||
|
from bleak.backends.device import BLEDevice
|
||||||
|
from bleak.backends.scanner import AdvertisementData
|
||||||
|
import bleak.exc
|
||||||
|
|
||||||
def scanner():
|
|
||||||
|
def discover_callback(device: BLEDevice, advertising_data: AdvertisementData):
|
||||||
|
print(f"[{advertising_data.rssi:-4d}] {device.address} - {device.name} with {len(advertising_data.service_uuids)} services")
|
||||||
|
|
||||||
|
|
||||||
|
async def discover_devices():
|
||||||
|
stop_event = asyncio.Event()
|
||||||
|
|
||||||
|
async with BleakScanner(discover_callback):
|
||||||
|
await stop_event.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
print("scanner called")
|
print("scanner called")
|
||||||
|
try:
|
||||||
|
asyncio.run(discover_devices())
|
||||||
|
except bleak.exc.BleakDBusError as exc:
|
||||||
|
print(f"ERROR: {exc}")
|
||||||
|
|
Loading…
Reference in New Issue