Skip to content

Commit

Permalink
Improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonarddeR committed Dec 14, 2024
1 parent 791e5d7 commit 73c4152
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions source/hwPortUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __str__(self):


PSP_DEVINFO_DATA = ctypes.POINTER(SP_DEVINFO_DATA)
DeviceInfoT = dict[str, str | None]


class SP_DEVICE_INTERFACE_DATA(ctypes.Structure):
Expand Down Expand Up @@ -159,7 +160,7 @@ def _isDebug():
return config.conf["debugLog"]["hwIo"]


def _getBluetoothPortInfo(regKey: int, hwID: str) -> dict:
def _getBluetoothPortInfo(regKey: int, hwID: str) -> DeviceInfoT:
info = {}
try:
port = info["port"] = winreg.QueryValueEx(regKey, "PortName")[0]
Expand Down Expand Up @@ -210,7 +211,7 @@ def _getBluetoothPortInfo(regKey: int, hwID: str) -> dict:
return info


def listComPorts(onlyAvailable: bool = True) -> typing.Iterator[dict]:
def listComPorts(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]:
"""List com ports on the system.
:param onlyAvailable: Only return ports that are currently available.
:return: Dicts including keys of port, friendlyName and hardwareID.
Expand Down Expand Up @@ -429,7 +430,7 @@ def __str__(self):
SetupDiDestroyDeviceInfoList(g_hdi)


def listUsbDevices(onlyAvailable: bool = True) -> typing.Iterator[dict]:
def listUsbDevices(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]:
"""List USB devices on the system.
:param onlyAvailable: Only return devices that are currently available.
:return: Generates dicts including keys of usbID (VID and PID), devicePath and hardwareID.
Expand Down Expand Up @@ -497,10 +498,10 @@ def __init__(self, **kwargs):
super().__init__(Size=ctypes.sizeof(HIDD_ATTRIBUTES), **kwargs)


_getHidInfoCache: dict[str, dict] = {}
_getHidInfoCache: dict[str, DeviceInfoT] = {}


def _getHidInfo(hwId: str, path: str) -> dict[str, str | None]:
def _getHidInfo(hwId: str, path: str) -> DeviceInfoT:
info = {
"hardwareID": hwId,
"devicePath": path,
Expand Down Expand Up @@ -576,7 +577,7 @@ def _getHidInfo(hwId: str, path: str) -> dict[str, str | None]:
_hidGuid = None


def listHidDevices(onlyAvailable: bool = True) -> typing.Iterator[dict]:
def listHidDevices(onlyAvailable: bool = True) -> typing.Iterator[DeviceInfoT]:
"""List HID devices on the system.
@param onlyAvailable: Only return devices that are currently available.
@return: Generates dicts including keys such as hardwareID,
Expand Down

0 comments on commit 73c4152

Please sign in to comment.