Fix zwave_js port enumeration (#81020)

This commit is contained in:
Martin Hjelmare 2022-10-26 17:12:30 +02:00 committed by GitHub
parent abb3ce6d69
commit a1a0284e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -126,15 +126,20 @@ def get_usb_ports() -> dict[str, str]:
ports = list_ports.comports() ports = list_ports.comports()
port_descriptions = {} port_descriptions = {}
for port in ports: for port in ports:
usb_device = usb.usb_device_from_port(port) vid: str | None = None
dev_path = usb.get_serial_by_id(usb_device.device) pid: str | None = None
if port.vid is not None and port.pid is not None:
usb_device = usb.usb_device_from_port(port)
vid = usb_device.vid
pid = usb_device.pid
dev_path = usb.get_serial_by_id(port.device)
human_name = usb.human_readable_device_name( human_name = usb.human_readable_device_name(
dev_path, dev_path,
usb_device.serial_number, port.serial_number,
usb_device.manufacturer, port.manufacturer,
usb_device.description, port.description,
usb_device.vid, vid,
usb_device.pid, pid,
) )
port_descriptions[dev_path] = human_name port_descriptions[dev_path] = human_name
return port_descriptions return port_descriptions

View File

@ -162,7 +162,12 @@ def mock_list_ports_fixture(serial_port) -> Generator[MagicMock, None, None]:
another_port.description = "New serial port" another_port.description = "New serial port"
another_port.serial_number = "5678" another_port.serial_number = "5678"
another_port.pid = 8765 another_port.pid = 8765
mock_list_ports.return_value = [serial_port, another_port] no_vid_port = copy(serial_port)
no_vid_port.device = "/no_vid"
no_vid_port.description = "Port without vid"
no_vid_port.serial_number = "9123"
no_vid_port.vid = None
mock_list_ports.return_value = [serial_port, another_port, no_vid_port]
yield mock_list_ports yield mock_list_ports