From b7be0254ef81b3f24b054bf9fe1e89556927272b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Sun, 18 Oct 2026 10:52:00 -0500 Subject: [PATCH] pb-service: keep the spaces that belong to a hub's name The firmware builds its Bluetooth name as the hub's name, one space and "(MINDSTORMS EV3)" or "(MINDSTORMS NXT)" (pbsys_host_get_hub_display_name). Taking the type off stripped every space around the name, so a hub named " Bumblebee " was listed as "Bumblebee", and a name filter, which matches exactly, could not find it. Only the one separating space goes now. --- packages/pb-service/src/pb_service/hub/rfcomm/port.py | 8 +++++++- packages/pb-service/tests/test_rfcomm_naming.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/pb-service/src/pb_service/hub/rfcomm/port.py b/packages/pb-service/src/pb_service/hub/rfcomm/port.py index bc2dc34..cb1653c 100644 --- a/packages/pb-service/src/pb_service/hub/rfcomm/port.py +++ b/packages/pb-service/src/pb_service/hub/rfcomm/port.py @@ -103,7 +103,13 @@ def split_hub_name(name: str | None) -> tuple[str | None, HubType | None]: if kind is None: return name, None - return name[:start].strip() or None, kind + # The firmware joins the two with exactly one space (name, then + # " (" PBSYS_CONFIG_HUB_TYPE_STR ")", in pbsys_host_get_hub_display_name), + # so only that one goes. Any other spaces are the owner's, and the hub + # reports its name with them, which is what a name filter is matched on. + bare = name[:start].removesuffix(" ") + + return bare or None, kind class ChannelPipe: diff --git a/packages/pb-service/tests/test_rfcomm_naming.py b/packages/pb-service/tests/test_rfcomm_naming.py index 14051e0..20447b6 100644 --- a/packages/pb-service/tests/test_rfcomm_naming.py +++ b/packages/pb-service/tests/test_rfcomm_naming.py @@ -24,6 +24,9 @@ ("Pybricks (MINDSTORMS NXT)", "Pybricks", HubType.NXT), # The whole name can be the suffix if the hub was never named. ("(MINDSTORMS EV3)", None, HubType.EV3), + # Only the firmware's one separating space goes. The rest belongs to + # the name, which the hub reports with them, and filters match it. + (" Bumblebee (MINDSTORMS EV3)", " Bumblebee ", HubType.EV3), ], ) def test_the_firmware_suffix_names_the_brick(