mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Create new usb constants (#60086)
This commit is contained in:
parent
31d4239b64
commit
263101b2ab
@ -6,7 +6,7 @@ import fnmatch
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from typing import TypedDict
|
from typing import Final, TypedDict
|
||||||
|
|
||||||
from serial.tools.list_ports import comports
|
from serial.tools.list_ports import comports
|
||||||
from serial.tools.list_ports_common import ListPortInfo
|
from serial.tools.list_ports_common import ListPortInfo
|
||||||
@ -31,6 +31,15 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
REQUEST_SCAN_COOLDOWN = 60 # 1 minute cooldown
|
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):
|
class UsbServiceInfo(TypedDict):
|
||||||
"""Prepared info from usb entries."""
|
"""Prepared info from usb entries."""
|
||||||
|
|
||||||
@ -171,20 +180,20 @@ class USBDiscovery:
|
|||||||
self.seen.add(device_tuple)
|
self.seen.add(device_tuple)
|
||||||
matched = []
|
matched = []
|
||||||
for matcher in self.usb:
|
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
|
continue
|
||||||
if "pid" in matcher and device.pid != matcher["pid"]:
|
if ATTR_PID in matcher and device.pid != matcher[ATTR_PID]:
|
||||||
continue
|
continue
|
||||||
if "serial_number" in matcher and not _fnmatch_lower(
|
if ATTR_SERIAL_NUMBER in matcher and not _fnmatch_lower(
|
||||||
device.serial_number, matcher["serial_number"]
|
device.serial_number, matcher[ATTR_SERIAL_NUMBER]
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
if "manufacturer" in matcher and not _fnmatch_lower(
|
if ATTR_MANUFACTURER in matcher and not _fnmatch_lower(
|
||||||
device.manufacturer, matcher["manufacturer"]
|
device.manufacturer, matcher[ATTR_MANUFACTURER]
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
if "description" in matcher and not _fnmatch_lower(
|
if ATTR_DESCRIPTION in matcher and not _fnmatch_lower(
|
||||||
device.description, matcher["description"]
|
device.description, matcher[ATTR_DESCRIPTION]
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
matched.append(matcher)
|
matched.append(matcher)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user