Skip to content

Commit fdbe293

Browse files
Hide HA Connect Zigbee adapters in Z-Wave serial port selector (#154923)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
1 parent aa67b46 commit fdbe293

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

homeassistant/components/zwave_js/config_flow.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
"USA",
125125
]
126126

127+
# USB devices to ignore in serial port selection (non-Z-Wave devices)
128+
# Format: (manufacturer, description)
129+
IGNORED_USB_DEVICES = {
130+
("Nabu Casa", "SkyConnect v1.0"),
131+
("Nabu Casa", "Home Assistant Connect ZBT-1"),
132+
("Nabu Casa", "ZBT-2"),
133+
}
134+
127135

128136
def get_manual_schema(user_input: dict[str, Any]) -> vol.Schema:
129137
"""Return a schema for the manual step."""
@@ -155,6 +163,9 @@ def get_usb_ports() -> dict[str, str]:
155163
ports = list_ports.comports()
156164
port_descriptions = {}
157165
for port in ports:
166+
if (port.manufacturer, port.description) in IGNORED_USB_DEVICES:
167+
continue
168+
158169
vid: str | None = None
159170
pid: str | None = None
160171
if port.vid is not None and port.pid is not None:

tests/components/zwave_js/test_config_flow.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,6 +4944,51 @@ async def test_get_usb_ports_single_valid_port() -> None:
49444944
]
49454945

49464946

4947+
async def test_get_usb_ports_ignored_devices() -> None:
4948+
"""Test that get_usb_ports filters out ignored non-Z-Wave devices."""
4949+
mock_ports = [
4950+
ListPortInfo("/dev/ttyUSB0"),
4951+
ListPortInfo("/dev/ttyUSB1"),
4952+
ListPortInfo("/dev/ttyUSB2"),
4953+
ListPortInfo("/dev/ttyUSB3"),
4954+
ListPortInfo("/dev/ttyUSB4"),
4955+
ListPortInfo("/dev/ttyUSB5"),
4956+
]
4957+
# ZBT-2, should be filtered
4958+
mock_ports[0].manufacturer = "Nabu Casa"
4959+
mock_ports[0].description = "ZBT-2"
4960+
4961+
# ZBT-1, should be filtered
4962+
mock_ports[2].manufacturer = "Nabu Casa"
4963+
mock_ports[2].description = "Home Assistant Connect ZBT-1"
4964+
4965+
# SkyConnect, should be filtered
4966+
mock_ports[1].manufacturer = "Nabu Casa"
4967+
mock_ports[1].description = "SkyConnect v1.0"
4968+
4969+
# ZWA-2, should be shown
4970+
mock_ports[3].manufacturer = "Nabu Casa"
4971+
mock_ports[3].description = "ZWA-2"
4972+
4973+
# unknown device with manufacturer/description, should be shown
4974+
mock_ports[4].manufacturer = "Another Manufacturer"
4975+
mock_ports[4].description = "Z-Wave USB Adapter"
4976+
4977+
# unknown device with no manufacturer/description, should be shown
4978+
mock_ports[5].manufacturer = None
4979+
mock_ports[5].description = None
4980+
4981+
with patch("serial.tools.list_ports.comports", return_value=mock_ports):
4982+
result = get_usb_ports()
4983+
descriptions = list(result.values())
4984+
4985+
assert descriptions == [
4986+
"ZWA-2 - /dev/ttyUSB3, s/n: n/a - Nabu Casa",
4987+
"Z-Wave USB Adapter - /dev/ttyUSB4, s/n: n/a - Another Manufacturer",
4988+
"/dev/ttyUSB5, s/n: n/a",
4989+
]
4990+
4991+
49474992
@pytest.mark.usefixtures("supervisor", "addon_not_installed", "addon_info")
49484993
async def test_intent_recommended_user(
49494994
hass: HomeAssistant,

0 commit comments

Comments
 (0)