Droid discovery extracted to function.
This commit is contained in:
parent
88e5024585
commit
593a71ec73
17
droid.py
17
droid.py
|
@ -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:
|
||||||
|
if not retry:
|
||||||
|
print("Droid discovery timed out.")
|
||||||
|
return
|
||||||
|
else:
|
||||||
print("Droid discovery timed out. Retrying...")
|
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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user