Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions homeassistant/components/usb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import os
import sys
from typing import TypedDict
from typing import Final, TypedDict

from serial.tools.list_ports import comports
from serial.tools.list_ports_common import ListPortInfo
Expand All @@ -31,6 +31,15 @@
REQUEST_SCAN_COOLDOWN = 60 # 1 minute cooldown


# Attributes for UsbServiceInfo
ATTR_DESCRIPTION: Final = "description"
ATTR_DEVICE: Final = "device"
ATTR_MANUFACTURER: Final = "manufacturer"
ATTR_PID: Final = "pid"
ATTR_SERIAL_NUMBER: Final = "serial_number"
ATTR_VID: Final = "vid"


class UsbServiceInfo(TypedDict):
"""Prepared info from usb entries."""

Expand Down Expand Up @@ -171,20 +180,20 @@ def _async_process_discovered_usb_device(self, device: USBDevice) -> None:
self.seen.add(device_tuple)
matched = []
for matcher in self.usb:
if "vid" in matcher and device.vid != matcher["vid"]:
if ATTR_VID in matcher and device.vid != matcher[ATTR_VID]:
continue
if "pid" in matcher and device.pid != matcher["pid"]:
if ATTR_PID in matcher and device.pid != matcher[ATTR_PID]:
continue
if "serial_number" in matcher and not _fnmatch_lower(
device.serial_number, matcher["serial_number"]
if ATTR_SERIAL_NUMBER in matcher and not _fnmatch_lower(
device.serial_number, matcher[ATTR_SERIAL_NUMBER]
):
continue
if "manufacturer" in matcher and not _fnmatch_lower(
device.manufacturer, matcher["manufacturer"]
if ATTR_MANUFACTURER in matcher and not _fnmatch_lower(
device.manufacturer, matcher[ATTR_MANUFACTURER]
):
continue
if "description" in matcher and not _fnmatch_lower(
device.description, matcher["description"]
if ATTR_DESCRIPTION in matcher and not _fnmatch_lower(
device.description, matcher[ATTR_DESCRIPTION]
):
continue
matched.append(matcher)
Expand Down