diff --git a/homeassistant/components/zwave_js/config_flow.py b/homeassistant/components/zwave_js/config_flow.py index 45b6f0b2a43e..5519942c4441 100644 --- a/homeassistant/components/zwave_js/config_flow.py +++ b/homeassistant/components/zwave_js/config_flow.py @@ -124,6 +124,14 @@ RF_REGIONS = [ "USA", ] +# USB devices to ignore in serial port selection (non-Z-Wave devices) +# Format: (manufacturer, description) +IGNORED_USB_DEVICES = { + ("Nabu Casa", "SkyConnect v1.0"), + ("Nabu Casa", "Home Assistant Connect ZBT-1"), + ("Nabu Casa", "ZBT-2"), +} + def get_manual_schema(user_input: dict[str, Any]) -> vol.Schema: """Return a schema for the manual step.""" @@ -155,6 +163,9 @@ def get_usb_ports() -> dict[str, str]: ports = list_ports.comports() port_descriptions = {} for port in ports: + if (port.manufacturer, port.description) in IGNORED_USB_DEVICES: + continue + vid: str | None = None pid: str | None = None if port.vid is not None and port.pid is not None: diff --git a/tests/components/zwave_js/test_config_flow.py b/tests/components/zwave_js/test_config_flow.py index 30c1de77076b..40b648a3033a 100644 --- a/tests/components/zwave_js/test_config_flow.py +++ b/tests/components/zwave_js/test_config_flow.py @@ -4944,6 +4944,51 @@ async def test_get_usb_ports_single_valid_port() -> None: ] +async def test_get_usb_ports_ignored_devices() -> None: + """Test that get_usb_ports filters out ignored non-Z-Wave devices.""" + mock_ports = [ + ListPortInfo("/dev/ttyUSB0"), + ListPortInfo("/dev/ttyUSB1"), + ListPortInfo("/dev/ttyUSB2"), + ListPortInfo("/dev/ttyUSB3"), + ListPortInfo("/dev/ttyUSB4"), + ListPortInfo("/dev/ttyUSB5"), + ] + # ZBT-2, should be filtered + mock_ports[0].manufacturer = "Nabu Casa" + mock_ports[0].description = "ZBT-2" + + # ZBT-1, should be filtered + mock_ports[2].manufacturer = "Nabu Casa" + mock_ports[2].description = "Home Assistant Connect ZBT-1" + + # SkyConnect, should be filtered + mock_ports[1].manufacturer = "Nabu Casa" + mock_ports[1].description = "SkyConnect v1.0" + + # ZWA-2, should be shown + mock_ports[3].manufacturer = "Nabu Casa" + mock_ports[3].description = "ZWA-2" + + # unknown device with manufacturer/description, should be shown + mock_ports[4].manufacturer = "Another Manufacturer" + mock_ports[4].description = "Z-Wave USB Adapter" + + # unknown device with no manufacturer/description, should be shown + mock_ports[5].manufacturer = None + mock_ports[5].description = None + + with patch("serial.tools.list_ports.comports", return_value=mock_ports): + result = get_usb_ports() + descriptions = list(result.values()) + + assert descriptions == [ + "ZWA-2 - /dev/ttyUSB3, s/n: n/a - Nabu Casa", + "Z-Wave USB Adapter - /dev/ttyUSB4, s/n: n/a - Another Manufacturer", + "/dev/ttyUSB5, s/n: n/a", + ] + + @pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info") async def test_intent_recommended_user( hass: HomeAssistant,