Home Assistant Unofficial Reference 2024.12.1
utils.py
Go to the documentation of this file.
1 """The USB Discovery integration."""
2 
3 from __future__ import annotations
4 
5 from serial.tools.list_ports_common import ListPortInfo
6 
7 from .models import USBDevice
8 
9 
10 def usb_device_from_port(port: ListPortInfo) -> USBDevice:
11  """Convert serial ListPortInfo to USBDevice."""
12  return USBDevice(
13  device=port.device,
14  vid=f"{hex(port.vid)[2:]:0>4}".upper(),
15  pid=f"{hex(port.pid)[2:]:0>4}".upper(),
16  serial_number=port.serial_number,
17  manufacturer=port.manufacturer,
18  description=port.description,
19  )
USBDevice usb_device_from_port(ListPortInfo port)
Definition: utils.py:10