def serial_finder(data):
    """
    Find controller serial and faucet_serial from the setup page.

    <select id="id_select_controller2" name="select_controller" >
        <option value='0' selected='selected'>1 - Controller001</option>
    </select>

    :param data: text to be parsed
    :type data: BeautilSoup object
    :return: a dict with controller_serial and faucet_serial
    :rtype: dict
    :raises IndexError: if controller_serial was not found on the data
    """
    if not isinstance(data, BeautifulSoup):
        raise TypeError("Function requires BeautifulSoup HTML element.")

    try:

        # The setup page contains a select box for each controller and each
        # faucet
        controllersElement = data.find_all('select',
                                           {'id': 'id_select_controller2'})

        faucetsElement = data.find_all('select',
                                       {'id': 'id_select_faucet2'})

        controllerSerial = controllersElement[0].text.split('-')[1].strip()
        faucetSerial = faucetsElement[0].text.split('-')[1].strip()

        # currently only one faucet is supported on the code
        # we have plans to support it in the future
        parsed_dict = {}
        parsed_dict['controller_serial'] = controllerSerial
        parsed_dict['faucet_serial'] = [faucetSerial]
        return parsed_dict

    except (AttributeError, IndexError, ValueError):
        raise RainCloudyException(
            'Could not find any valid controller or faucet')
def serial_finder ( data ) : if not isinstance ( data , BeautifulSoup ) : raise TypeError ( "Function requires BeautifulSoup HTML element." ) try : controllersElement = data . find_all ( 'select' , { 'id' : 'id_select_controller2' } ) faucetsElement = data . find_all ( 'select' , { 'id' : 'id_select_faucet2' } ) controllerSerial = controllersElement [ 0 ] . text . split ( '-' ) [ 1 ] . strip ( ) faucetSerial = faucetsElement [ 0 ] . text . split ( '-' ) [ 1 ] . strip ( ) parsed_dict = { } parsed_dict [ 'controller_serial' ] = controllerSerial parsed_dict [ 'faucet_serial' ] = [ faucetSerial ] return parsed_dict except ( AttributeError , IndexError , ValueError ) : raise RainCloudyException ( 'Could not find any valid controller or faucet' )
Find controller serial and faucet_serial from the setup page.

    <select id="id_select_controller2" name="select_controller" >
        <option value='0' selected='selected'>1 - Controller001</option>
    </select>

    :param data: text to be parsed
    :type data: BeautilSoup object
    :return: a dict with controller_serial and faucet_serial
    :rtype: dict
    :raises IndexError: if controller_serial was not found on the data