Skip to content

Commit 19ed43c

Browse files
committed
cli/flash: remove name filtering
The hub_name argument was just supposed to be the new name to include when flashing the firmware. It caused connecting to hubs to fail because the bootloader mode never matched the name.
1 parent 1e12e95 commit 19ed43c

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.0.0-alpha.23] - 2022-01-17
10+
11+
### Fixed
12+
- Fixed ``pybricksdev flash`` command with ``--name`` argument not connecting.
13+
914
## [1.0.0-alpha.22] - 2022-01-17
1015

1116
### Added
@@ -198,7 +203,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
198203

199204

200205

201-
[Unreleased]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.22..HEAD
206+
[Unreleased]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.23..HEAD
207+
[1.0.0-alpha.23]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.22...v1.0.0-alpha.23
202208
[1.0.0-alpha.22]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.21...v1.0.0-alpha.22
203209
[1.0.0-alpha.21]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.20...v1.0.0-alpha.21
204210
[1.0.0-alpha.20]: https://github.com/pybricks/pybricksdev/compare/v1.0.0-alpha.19...v1.0.0-alpha.20

pybricksdev/cli/flash.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,17 @@
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)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pybricksdev"
3-
version = "1.0.0-alpha.22"
3+
version = "1.0.0-alpha.23"
44
description = "Pybricks developer tools"
55
authors = ["The Pybricks Authors <[email protected]>"]
66
maintainers = ["Laurens Valk <[email protected]>", "David Lechner <[email protected]>" ]

0 commit comments

Comments
 (0)