Skip to content

Commit bdb9163

Browse files
committed
ble: move print out of find_device()
Since this is a library function, it is best that it doesn't print. It also lets us print a more specialized message in command line tools.
1 parent fbb8770 commit bdb9163

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pybricksdev/ble/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ async def find_device(
3939
asyncio.TimeoutError:
4040
Device was not found within the timeout.
4141
"""
42-
print(f"Searching for {name or service}")
4342

4443
def match_uuid_and_name(device: BLEDevice, adv: AdvertisementData):
4544
if service not in adv.service_uuids:

pybricksdev/cli/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ async def run(self, args: argparse.Namespace):
144144
elif args.conntype == "ble":
145145
# It is a Pybricks Hub with BLE. Device name or address is given.
146146
hub = PybricksHub()
147+
print(f"Searching for {args.name or 'any hub with Pybricks service'}...")
147148
device_or_address = await find_device(args.name)
149+
148150
elif args.conntype == "usb" and args.name == "lego":
149151
# It's LEGO stock firmware Hub with USB.
150152
hub = USBRPCConnection()
@@ -195,7 +197,14 @@ async def run(self, args: argparse.Namespace):
195197
from ..ble import find_device
196198
from ..flash import BootloaderConnection
197199

198-
device = await find_device(service=LWP3_BOOTLOADER_SERVICE_UUID)
200+
print("Searching for LEGO Bootloader...")
201+
202+
try:
203+
device = await find_device(service=LWP3_BOOTLOADER_SERVICE_UUID)
204+
except asyncio.TimeoutError:
205+
print("timed out")
206+
return
207+
199208
print("Found:", device)
200209
updater = BootloaderConnection()
201210
await updater.connect(device)

0 commit comments

Comments
 (0)