@@ -233,21 +233,35 @@ def is_pybricks_usb(dev):
233233 await hub .download (script_path )
234234
235235 if args .stay_connected :
236- response_options = ["Recompile and Run" , "Recompile and Download" , "Exit" ]
236+ response_options = [
237+ "Recompile and Run" ,
238+ "Recompile and Download" ,
239+ "Exit" ,
240+ ]
237241 while True :
238242 try :
239- response = await hub .race_user_program_start (questionary .select ("Would you like to re-compile your code?" , response_options ).ask_async ())
243+ response = await hub .race_user_program_start (
244+ questionary .select (
245+ "Would you like to re-compile your code?" ,
246+ response_options ,
247+ ).ask_async ()
248+ )
240249 except RuntimeError as e :
241250
242251 async def reconnect_hub ():
243252 if await questionary .confirm (
244- "\n The hub has been disconnected. Would you like to re-connect?" ).ask_async ():
253+ "\n The hub has been disconnected. Would you like to re-connect?"
254+ ).ask_async ():
245255 if args .conntype == "ble" :
246- print (f"Searching for { args .name or 'any hub with Pybricks service' } ..." )
256+ print (
257+ f"Searching for { args .name or 'any hub with Pybricks service' } ..."
258+ )
247259 device_or_address = await find_ble (args .name )
248260 hub = PybricksHubBLE (device_or_address )
249261 elif args .conntype == "usb" :
250- device_or_address = find_usb (custom_match = is_pybricks_usb )
262+ device_or_address = find_usb (
263+ custom_match = is_pybricks_usb
264+ )
251265 hub = PybricksHubUSB (device_or_address )
252266
253267 await hub .connect ()
@@ -259,20 +273,26 @@ async def reconnect_hub():
259273 else :
260274 exit ()
261275
262- if hub .status_observable .value & StatusFlag .POWER_BUTTON_PRESSED :
276+ if (hub .status_observable .value
277+ & StatusFlag .POWER_BUTTON_PRESSED
278+ ):
263279 try :
264280 await hub ._wait_for_user_program_stop (2.1 )
265281 continue
266282
267283 except RuntimeError as e :
268- if hub .connection_state_observable .value == ConnectionState .DISCONNECTED :
284+ if (hub .connection_state_observable .value
285+ == ConnectionState .DISCONNECTED
286+ ):
269287 hub = await reconnect_hub ()
270288 continue
271289
272290 else :
273291 raise e
274292
275- elif hub .connection_state_observable .value == ConnectionState .DISCONNECTED :
293+ elif (hub .connection_state_observable .value
294+ == ConnectionState .DISCONNECTED
295+ ):
276296 # let terminal cool off before making a new prompt
277297 await asyncio .sleep (0.3 )
278298
@@ -283,20 +303,19 @@ async def reconnect_hub():
283303 raise e
284304
285305 with _get_script_path (args .file ) as script_path :
286- if response == response_options [0 ]:
287- await hub .run (script_path , True )
288- elif response == response_options [1 ]:
289- await hub .download (script_path )
290- else :
291- exit (1 )
306+ if response == response_options [0 ]:
307+ await hub .run (script_path , True )
308+ elif response == response_options [1 ]:
309+ await hub .download (script_path )
310+ else :
311+ exit (1 )
292312
293313 finally :
294314 await hub .disconnect ()
295315
296316
297317class Flash (Tool ):
298318
299-
300319 def add_parser (self , subparsers : argparse ._SubParsersAction ):
301320 parser = subparsers .add_parser (
302321 "flash" , help = "flash firmware on a LEGO Powered Up device"
0 commit comments