import kp

def check_available_device():
    try:
        print("checking available devices")
        device_descriptors = kp.core.scan_devices()
        print("device_descriptors", device_descriptors)
        return device_descriptors
    except Exception as e:
        print(f"Error scanning devices: {e}")
        # 返回一個空的設備描述符或模擬數據
        class EmptyDescriptor:
            def __init__(self):
                self.device_descriptor_number = 0
                self.device_descriptor_list = []
        return EmptyDescriptor()

# def check_available_device():
    # # 模擬設備描述符
    # print("checking available devices")
    # class EmptyDescriptor:
    #     def __init__(self):
    #         self.device_descriptor_number = 0
    #         self.device_descriptor_list = [{
    #         "usb_port_id": 4,
    #         "vendor_id": "0x3231",
    #         "product_id": "0x720",
    #         "link_speed": "UsbSpeed.KP_USB_SPEED_SUPER",
    #         "kn_number": "0xB306224C",
    #         "is_connectable": True,
    #         "usb_port_path": "4-1",
    #         "firmware": "KDP2 Comp/F"
    #     },
    #     {
    #         "usb_port_id": 5,
    #         "vendor_id": "0x3231",
    #         "product_id": "0x520",
    #         "link_speed": "UsbSpeed.KP_USB_SPEED_SUPER",
    #         "kn_number": "0xB306224C",
    #         "is_connectable": True,
    #         "usb_port_path": "4-1",
    #         "firmware": "KDP2 Comp/F"
    #     }]
    # return EmptyDescriptor()
    # device_descriptors = [
    #     {
    #         "usb_port_id": 4,
    #         "vendor_id": "0x3231",
    #         "product_id": "0x720",
    #         "link_speed": "UsbSpeed.KP_USB_SPEED_SUPER",
    #         "kn_number": "0xB306224C",
    #         "is_connectable": True,
    #         "usb_port_path": "4-1",
    #         "firmware": "KDP2 Comp/F"
    #     },
    #     {
    #         "usb_port_id": 5,
    #         "vendor_id": "0x3231",
    #         "product_id": "0x520",
    #         "link_speed": "UsbSpeed.KP_USB_SPEED_SUPER",
    #         "kn_number": "0xB306224C",
    #         "is_connectable": True,
    #         "usb_port_path": "4-1",
    #         "firmware": "KDP2 Comp/F"
    #     }
    # ]
    # return device_descriptors

# def get_dongle_type(self, product_id):
        # for dongle_type in self.K_:
        #     if dongle_type.value == product_id:
        #         return dongle_type
        # return None