<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def add(name, beacon_data, **kwargs):
    '''
    Add a beacon on the minion

    Args:

        name (str):
            Name of the beacon to configure

        beacon_data (dict):
            Dictionary or list containing configuration for beacon.

    Returns:
        dict: Boolean and status message on success or failure of add.

    CLI Example:

    .. code-block:: bash

        salt '*' beacons.add ps "[{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]"

    '''
    ret = {'comment': 'Failed to add beacon {0}.'.format(name),
           'result': False}

    if name in list_(return_yaml=False, **kwargs):
        ret['comment'] = 'Beacon {0} is already configured.'.format(name)
        return ret

    # Check to see if a beacon_module is specified, if so, verify it is
    # valid and available beacon type.
    if any('beacon_module' in key for key in beacon_data):
        res = next(value for value in beacon_data if 'beacon_module' in value)
        beacon_name = res['beacon_module']
    else:
        beacon_name = name

    if beacon_name not in list_available(return_yaml=False, **kwargs):
        ret['comment'] = 'Beacon "{0}" is not available.'.format(beacon_name)
        return ret

    if 'test' in kwargs and kwargs['test']:
        ret['result'] = True
        ret['comment'] = 'Beacon: {0} would be added.'.format(name)
    else:
        try:
            # Attempt to load the beacon module so we have access to the
            # validate function
            eventer = salt.utils.event.get_event('minion', opts=__opts__)
            res = __salt__['event.fire']({'name': name,
                                          'beacon_data': beacon_data,
                                          'func': 'validate_beacon'},
                                         'manage_beacons')
            if res:
                event_ret = eventer.get_event(
                    tag='/salt/minion/minion_beacon_validation_complete',
                    wait=kwargs.get('timeout', 30))
                valid = event_ret['valid']
                vcomment = event_ret['vcomment']

            if not valid:
                ret['result'] = False
                ret['comment'] = ('Beacon {0} configuration invalid, '
                                  'not adding.\n{1}'.format(name, vcomment))
                return ret

        except KeyError:
            # Effectively a no-op, since we can't really return without an event
            # system
            ret['result'] = False
            ret['comment'] = 'Event module not available. Beacon add failed.'
            return ret

        try:
            res = __salt__['event.fire']({'name': name,
                                          'beacon_data': beacon_data,
                                          'func': 'add'}, 'manage_beacons')
            if res:
                event_ret = eventer.get_event(
                    tag='/salt/minion/minion_beacon_add_complete',
                    wait=kwargs.get('timeout', 30))
                if event_ret and event_ret['complete']:
                    beacons = event_ret['beacons']
                    if name in beacons and beacons[name] == beacon_data:
                        ret['result'] = True
                        ret['comment'] = 'Added beacon: {0}.'.format(name)
                elif event_ret:
                    ret['result'] = False
                    ret['comment'] = event_ret['comment']
                else:
                    ret['result'] = False
                    ret['comment'] = 'Did not receive the manage event ' \
                                     'before the timeout of {0}s' \
                                     ''.format(kwargs.get('timeout', 30))
                return ret
        except KeyError:
            # Effectively a no-op, since we can't really return without an event
            # system
            ret['result'] = False
            ret['comment'] = 'Event module not available. Beacon add failed.'
    return ret