mirror of
https://github.com/home-assistant/core
synced 2024-08-28 03:36:46 +02:00
19 lines
545 B
Python
19 lines
545 B
Python
"""The USB Discovery integration."""
|
|
from __future__ import annotations
|
|
|
|
from serial.tools.list_ports_common import ListPortInfo
|
|
|
|
from .models import USBDevice
|
|
|
|
|
|
def usb_device_from_port(port: ListPortInfo) -> USBDevice:
|
|
"""Convert serial ListPortInfo to USBDevice."""
|
|
return USBDevice(
|
|
device=port.device,
|
|
vid=f"{hex(port.vid)[2:]:0>4}".upper(),
|
|
pid=f"{hex(port.pid)[2:]:0>4}".upper(),
|
|
serial_number=port.serial_number,
|
|
manufacturer=port.manufacturer,
|
|
description=port.description,
|
|
)
|