1
mirror of https://github.com/home-assistant/core synced 2024-08-28 03:36:46 +02:00
ha-core/homeassistant/components/usb/utils.py
J. Nick Koston dc74a52f58
Add support for USB discovery (#54904)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-08-20 14:04:18 -05:00

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,
)