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(