qmk_firmware/lib/python/xap_client/client.py
2022-07-19 00:55:36 +01:00

37 lines
1004 B
Python

# Copyright 2022 QMK
# SPDX-License-Identifier: GPL-2.0-or-later
import hid
class XAPClient:
"""XAP device discovery
"""
@staticmethod
def devices(search: str = None) -> list[dict]:
"""Find compatible XAP devices
Args:
search: optional search string to filter results by
"""
def _is_xap_usage(x):
return x['usage_page'] == 0xFF51 and x['usage'] == 0x0058
def _is_filtered_device(x):
name = '%04x:%04x' % (x['vendor_id'], x['product_id'])
return name.lower().startswith(search.lower())
devices = filter(_is_xap_usage, hid.enumerate())
if search:
devices = filter(_is_filtered_device, devices)
return list(devices)
def connect(self, device: dict):
"""Connect to a given XAP device
Args:
device: item from a previous `XAPClient.devices()` call
"""
from .device import XAPDevice
return XAPDevice(device)