Create new usb constants (#60086)

This commit is contained in:
epenet 2021-11-22 01:14:42 +01:00 committed by GitHub
parent 31d4239b64
commit 263101b2ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ import fnmatch
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
@ -31,6 +31,15 @@ _LOGGER = logging.getLogger(__name__)
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."""
@ -171,20 +180,20 @@ class USBDiscovery:
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)