Make a nicer error when the robot isn't found.
This commit is contained in:
@@ -9,8 +9,7 @@ async def run():
|
|||||||
print([device.name for device in devices])
|
print([device.name for device in devices])
|
||||||
matching_devices = [device for device in devices if device.name==ble_name]
|
matching_devices = [device for device in devices if device.name==ble_name]
|
||||||
if len(matching_devices) == 0:
|
if len(matching_devices) == 0:
|
||||||
print(f"Could not find robot at {ble_name}")
|
raise RuntimeError("Could not find robot")
|
||||||
return
|
|
||||||
ble_device_info = matching_devices[0]
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Found robot {ble_device_info.name}...")
|
print(f"Found robot {ble_device_info.name}...")
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ class BleConnection:
|
|||||||
devices = await bleak.BleakScanner.discover(
|
devices = await bleak.BleakScanner.discover(
|
||||||
service_uuids=[self.ble_uuid]
|
service_uuids=[self.ble_uuid]
|
||||||
)
|
)
|
||||||
print(f"Found {len(devices)} devices")
|
matching_devices = [device for device in devices if device.name==self.ble_name]
|
||||||
print([device.name for device in devices])
|
if len(matching_devices) == 0:
|
||||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
raise RuntimeError("Could not find robot")
|
||||||
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Connecting to {ble_device_info.name}...")
|
print(f"Connecting to {ble_device_info.name}...")
|
||||||
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
||||||
await self.ble_client.connect()
|
await self.ble_client.connect()
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ class BleConnection:
|
|||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
print("Scanning for devices...")
|
print("Scanning for devices...")
|
||||||
devices = await bleak.BleakScanner.discover(service_uuids=[self.ble_uuid])
|
devices = await bleak.BleakScanner.discover(
|
||||||
print(f"Found {len(devices)} devices")
|
service_uuids=[self.ble_uuid]
|
||||||
print([device.name for device in devices])
|
)
|
||||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
matching_devices = [device for device in devices if device.name==self.ble_name]
|
||||||
|
if len(matching_devices) == 0:
|
||||||
|
raise RuntimeError("Could not find robot")
|
||||||
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Connecting to {ble_device_info.name}...")
|
print(f"Connecting to {ble_device_info.name}...")
|
||||||
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
||||||
await self.ble_client.connect()
|
await self.ble_client.connect()
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ class BleConnection:
|
|||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
print("Scanning for devices...")
|
print("Scanning for devices...")
|
||||||
devices = await bleak.BleakScanner.discover(service_uuids=[self.ble_uuid])
|
devices = await bleak.BleakScanner.discover(
|
||||||
print(f"Found {len(devices)} devices")
|
service_uuids=[self.ble_uuid]
|
||||||
print([device.name for device in devices])
|
)
|
||||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
matching_devices = [device for device in devices if device.name==self.ble_name]
|
||||||
|
if len(matching_devices) == 0:
|
||||||
|
raise RuntimeError("Could not find robot")
|
||||||
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Connecting to {ble_device_info.name}...")
|
print(f"Connecting to {ble_device_info.name}...")
|
||||||
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
||||||
await self.ble_client.connect()
|
await self.ble_client.connect()
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ class BleConnection:
|
|||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
print("Scanning for devices...")
|
print("Scanning for devices...")
|
||||||
devices = await bleak.BleakScanner.discover(service_uuids=[self.ble_uuid])
|
devices = await bleak.BleakScanner.discover(
|
||||||
print(f"Found {len(devices)} devices")
|
service_uuids=[self.ble_uuid]
|
||||||
print([device.name for device in devices])
|
)
|
||||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
matching_devices = [device for device in devices if device.name==self.ble_name]
|
||||||
|
if len(matching_devices) == 0:
|
||||||
|
raise RuntimeError("Could not find robot")
|
||||||
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Connecting to {ble_device_info.name}...")
|
print(f"Connecting to {ble_device_info.name}...")
|
||||||
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
||||||
await self.ble_client.connect()
|
await self.ble_client.connect()
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ class BleConnection:
|
|||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
print("Scanning for devices...")
|
print("Scanning for devices...")
|
||||||
devices = await bleak.BleakScanner.discover(service_uuids=[self.ble_uuid])
|
devices = await bleak.BleakScanner.discover(
|
||||||
print(f"Found {len(devices)} devices")
|
service_uuids=[self.ble_uuid]
|
||||||
print([device.name for device in devices])
|
)
|
||||||
ble_device_info = [device for device in devices if device.name==self.ble_name][0]
|
matching_devices = [device for device in devices if device.name==self.ble_name]
|
||||||
|
if len(matching_devices) == 0:
|
||||||
|
raise RuntimeError("Could not find robot")
|
||||||
|
ble_device_info = matching_devices[0]
|
||||||
print(f"Connecting to {ble_device_info.name}...")
|
print(f"Connecting to {ble_device_info.name}...")
|
||||||
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
self.ble_client = bleak.BleakClient(ble_device_info.address)
|
||||||
await self.ble_client.connect()
|
await self.ble_client.connect()
|
||||||
|
|||||||
Reference in New Issue
Block a user