# Path: fluxghost/g.py
# USBDEVS = {}


from threading import Thread
from glob import glob
from serial.tools import list_ports as _list_ports
from fluxclient.device.host2host_usb import USBProtocol, FluxUSBError
from fluxghost import g
import logging
import sys


def usb_interfaces_api_mixin(cls):
    class ClosedUsbDev(object):
        endpoint_profile = False

    class H2HInterfacesApi(cls):
        def __init__(self, *args, **kw):
            super().__init__(*args, **kw)

        def on_text_message(self, message):
            if message == "list":
                self.list_devices()
            elif message.startswith("open "):
                addr = int(message[5:])
                self.open_device(addr)
            elif message.startswith("close "):
                addr = int(message[6:])
                self.close_device(addr)

        def on_binary_message(self, message):
            pass

        def on_close(self, message):
            pass

        def get_devices(self):
            usbdevs = {}
            ifces = USBProtocol.get_interfaces()
            for i in ifces:

# Path: fluxghost/g.py
# USBDEVS = {}


# Path: fluxghost/api/usb_interfaces.py
from threading import Thread
from glob import glob
from serial.tools import list_ports as _list_ports
from fluxclient.device.host2host_usb import USBProtocol, FluxUSBError
from fluxghost import g
import logging
import sys



def usb_interfaces_api_mixin(cls):
    class ClosedUsbDev(object):
        endpoint_profile = False

    class H2HInterfacesApi(cls):
        def __init__(self, *args, **kw):
            super().__init__(*args, **kw)

        def on_text_message(self, message):
            if message == "list":
                self.list_devices()
            elif message.startswith("open "):
                addr = int(message[5:])
                self.open_device(addr)
            elif message.startswith("close "):
                addr = int(message[6:])
                self.close_device(addr)

        def on_binary_message(self, message):
            pass

        def on_close(self, message):
            pass

        def get_devices(self):
            usbdevs = {}
            ifces = USBProtocol.get_interfaces()
            for i in ifces:

                if i.address in g.USBDEVS: