Droid discovery extracted to function.

This commit is contained in:
hornet 2022-10-09 20:54:48 -04:00
parent 88e5024585
commit 593a71ec73

View File

@ -102,21 +102,34 @@ def findDroid(candidate, data):
else: else:
return False return False
async def main(): async def discoverDroid(retry=False):
myDroid = None myDroid = None
while myDroid is None or myDroid == "None": while retry and myDroid is None:
try: try:
myDroid = await BleakScanner.find_device_by_filter(findDroid) myDroid = await BleakScanner.find_device_by_filter(findDroid)
if myDroid is None: if myDroid is None:
print("Droid discovery timed out. Retrying...") if not retry:
print("Droid discovery timed out.")
return
else:
print("Droid discovery timed out. Retrying...")
continue
except BleakError as err: except BleakError as err:
print("Droid discovery failed. Retrying...") print("Droid discovery failed. Retrying...")
continue continue
print (f"Astromech successfully discovered: [ {myDroid} ]")
print (f"Astromech successfully discovered: [ {myDroid} ]")
d = Droid(myDroid) d = Droid(myDroid)
return d
async def main():
d = await discoverDroid()
try: try:
await d.connect() await d.connect()