def instantiate_device(virtual_dev, config, loop):
    """Find a virtual device by name and instantiate it

    Args:
        virtual_dev (string): The name of the pkg_resources entry point corresponding to
            the device.  It should be in group iotile.virtual_device.  If virtual_dev ends
            in .py, it is interpreted as a python script and loaded directly from the script.
        config (dict): A dictionary with a 'device' key with the config info for configuring
            this virtual device.  This is optional.

    Returns:
        VirtualIOTileDevice: The instantiated subclass of VirtualIOTileDevice
    """
    conf = {}
    if 'device' in config:
        conf = config['device']

    # If we're given a path to a script, try to load and use that rather than search for an installed module
    try:
        reg = ComponentRegistry()

        if virtual_dev.endswith('.py'):
            _name, dev = reg.load_extension(virtual_dev, class_filter=VirtualIOTileDevice, unique=True)
        else:
            _name, dev = reg.load_extensions('iotile.virtual_device', name_filter=virtual_dev,
                                             class_filter=VirtualIOTileDevice,
                                             product_name="virtual_device", unique=True)

        return dev(conf)
    except ArgumentError as err:
        print("ERROR: Could not load virtual device (%s): %s" % (virtual_dev, err.msg))
        sys.exit(1)
def instantiate_device ( virtual_dev , config , loop ) : conf = { } if 'device' in config : conf = config [ 'device' ] try : reg = ComponentRegistry ( ) if virtual_dev . endswith ( '.py' ) : _name , dev = reg . load_extension ( virtual_dev , class_filter = VirtualIOTileDevice , unique = True ) else : _name , dev = reg . load_extensions ( 'iotile.virtual_device' , name_filter = virtual_dev , class_filter = VirtualIOTileDevice , product_name = "virtual_device" , unique = True ) return dev ( conf ) except ArgumentError as err : print ( "ERROR: Could not load virtual device (%s): %s" % ( virtual_dev , err . msg ) ) sys . exit ( 1 )
Find a virtual device by name and instantiate it

    Args:
        virtual_dev (string): The name of the pkg_resources entry point corresponding to
            the device.  It should be in group iotile.virtual_device.  If virtual_dev ends
            in .py, it is interpreted as a python script and loaded directly from the script.
        config (dict): A dictionary with a 'device' key with the config info for configuring
            this virtual device.  This is optional.

    Returns:
        VirtualIOTileDevice: The instantiated subclass of VirtualIOTileDevice