Fix zwave_js port enumeration (#81020)
This commit is contained in:
parent
abb3ce6d69
commit
a1a0284e81
2 changed files with 18 additions and 8 deletions
|
@ -126,15 +126,20 @@ def get_usb_ports() -> dict[str, str]:
|
|||
ports = list_ports.comports()
|
||||
port_descriptions = {}
|
||||
for port in ports:
|
||||
usb_device = usb.usb_device_from_port(port)
|
||||
dev_path = usb.get_serial_by_id(usb_device.device)
|
||||
vid: str | None = None
|
||||
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(
|
||||
dev_path,
|
||||
usb_device.serial_number,
|
||||
usb_device.manufacturer,
|
||||
usb_device.description,
|
||||
usb_device.vid,
|
||||
usb_device.pid,
|
||||
port.serial_number,
|
||||
port.manufacturer,
|
||||
port.description,
|
||||
vid,
|
||||
pid,
|
||||
)
|
||||
port_descriptions[dev_path] = human_name
|
||||
return port_descriptions
|
||||
|
|
|
@ -162,7 +162,12 @@ def mock_list_ports_fixture(serial_port) -> Generator[MagicMock, None, None]:
|
|||
another_port.description = "New serial port"
|
||||
another_port.serial_number = "5678"
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue