5757"""
5858
5959
60- def match_hub (
61- hub_kind : HubKind , hub_name : Optional [str ], adv : AdvertisementData
62- ) -> bool :
60+ def match_hub (hub_kind : HubKind , adv : AdvertisementData ) -> bool :
6361 """
6462 Advertisement data matching function for filtering supported hubs.
6563
6664 Args:
6765 hub_kind: The hub type ID to match.
68- hub_name: An optional name to match to the "local name" in the
69- advertisement data.
7066 adv: The advertisemet data to check.
7167
7268 Returns:
7369 ``True`` if *adv* matches the criteria, otherwise ``False``.
7470 """
75- # hub name filtering is optional
76- if hub_name and adv .local_name != hub_name :
77- return False
78-
7971 # LEGO firmware uses manufacturer-specific data
8072
8173 lego_data = adv .manufacturer_data .get (LEGO_CID )
@@ -222,9 +214,7 @@ async def reboot_pybricks_to_bootloader(hub_kind: HubKind, device: BLEDevice) ->
222214 await download_and_run (client , REBOOT_SCRIPT )
223215
224216
225- async def flash_ble (
226- hub_kind : HubKind , hub_name : Optional [str ], firmware : bytes , metadata : dict
227- ):
217+ async def flash_ble (hub_kind : HubKind , firmware : bytes , metadata : dict ):
228218 """
229219 Flashes firmware to the hub using Bluetooth Low Energy.
230220
@@ -233,18 +223,17 @@ async def flash_ble(
233223
234224 Args:
235225 hub_kind: The hub type ID. Only hubs matching this ID will be discovered.
236- hub_name: If given, only hubs that advertise this name will be disovered.
237226 firmware: The raw firmware binary blob.
238227 metadata: The firmware metadata from the firmware.zip file.
239228 """
240229
241- print (f"Searching for { repr ( hub_name ) if hub_name else hub_kind .name } hub..." )
230+ print (f"Searching for { hub_kind .name } hub..." )
242231
243232 # scan for hubs in bootloader mode, running official LEGO firmware or
244233 # running Pybricks firmware
245234
246235 device = await BleakScanner .find_device_by_filter (
247- lambda _d , a : match_hub (hub_kind , hub_name , a ),
236+ lambda _d , a : match_hub (hub_kind , a ),
248237 service_uuids = [
249238 LWP3_BOOTLOADER_SERVICE_UUID ,
250239 LWP3_HUB_SERVICE_UUID ,
@@ -267,7 +256,7 @@ async def flash_ble(
267256 # if not previously in bootlaoder mode, scan again, this time only for bootloader
268257 if LWP3_BOOTLOADER_SERVICE_UUID not in device .metadata ["uuids" ]:
269258 device = await BleakScanner .find_device_by_filter (
270- lambda _d , a : match_hub (hub_kind , hub_name , a ),
259+ lambda _d , a : match_hub (hub_kind , a ),
271260 service_uuids = [
272261 LWP3_BOOTLOADER_SERVICE_UUID ,
273262 ],
@@ -284,18 +273,18 @@ async def flash_ble(
284273 await updater .flash (firmware , metadata )
285274
286275
287- async def flash_firmware (firmware_zip : BinaryIO , hub_name : Optional [str ]) -> None :
276+ async def flash_firmware (firmware_zip : BinaryIO , new_name : Optional [str ]) -> None :
288277 """
289278 Command line tool for flasing firmware.
290279
291280 Args:
292281 firmware_zip: The path to the ``firmware.zip`` file.
293- hub_name : Optional custom hub name.
282+ new_name : Optional custom hub name to be applied to the firmware image .
294283 """
295284
296285 print ("Creating firmware..." )
297286
298- firmware , metadata = await create_firmware (firmware_zip , hub_name )
287+ firmware , metadata = await create_firmware (firmware_zip , new_name )
299288 hub_kind = HubKind (metadata ["device-id" ])
300289
301290 if hub_kind in (HubKind .TECHNIC_SMALL , HubKind .TECHNIC_LARGE ):
@@ -331,4 +320,4 @@ async def flash_firmware(firmware_zip: BinaryIO, hub_name: Optional[str]) -> Non
331320 print ("Could not find hub in standard firmware mode. Trying DFU." )
332321 flash_dfu (firmware , metadata )
333322 else :
334- await flash_ble (hub_kind , hub_name , firmware , metadata )
323+ await flash_ble (hub_kind , firmware , metadata )
0 commit comments