コード例 #1
0
ファイル: forms_input.py プロジェクト: zhangfaquan/Mycodo
class InputAdd(FlaskForm):
    choices_inputs = []
    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    for each_input in list_inputs_sorted:
        value = '{inp},'.format(inp=each_input)
        name = '{manuf}: {name}'.format(
            manuf=dict_inputs[each_input]['input_manufacturer'],
            name=dict_inputs[each_input]['input_name'])

        if 'input_library' in dict_inputs[each_input]:
            name += ' ({lib})'.format(lib=dict_inputs[each_input]['input_library'])

        name += ': {meas}'.format(meas=dict_inputs[each_input]['measurements_name'])

        if 'interfaces' in dict_inputs[each_input]:
            for each_interface in dict_inputs[each_input]['interfaces']:
                tmp_value = '{val}{int}'.format(val=value, int=each_interface)
                tmp_name = '{name} ({int})'.format(name=name, int=each_interface)
                choices_inputs.append((tmp_value, tmp_name))
        else:
            choices_inputs.append((value, name))

    input_type = SelectField(
        choices=choices_inputs,
        validators=[DataRequired()]
    )
    input_add = SubmitField(TRANSLATIONS['add']['title'])
コード例 #2
0
class InputAdd(FlaskForm):
    choices_inputs = [('', lazy_gettext('Select Input to Add'))]
    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    for each_input in list_inputs_sorted:
        if 'interfaces' not in dict_inputs[each_input]:
            choices_inputs.append(
                ('{inp},'.format(inp=each_input),
                 '{manuf}: {name}: {meas}'.format(
                     manuf=dict_inputs[each_input]['input_manufacturer'],
                     name=dict_inputs[each_input]['input_name'],
                     meas=dict_inputs[each_input]['measurements_name'])))
        else:
            for each_interface in dict_inputs[each_input]['interfaces']:
                choices_inputs.append(
                    ('{inp},{int}'.format(inp=each_input, int=each_interface),
                     '{manuf}: {name}: {meas} ({int})'.format(
                         manuf=dict_inputs[each_input]['input_manufacturer'],
                         name=dict_inputs[each_input]['input_name'],
                         meas=dict_inputs[each_input]['measurements_name'],
                         int=each_interface)))

    input_type = SelectField(choices=choices_inputs,
                             validators=[DataRequired()])
    input_add = SubmitField(lazy_gettext('Add Input'))
コード例 #3
0
def test_add_all_input_devices_logged_in_as_admin(_, testapp):
    """ Verifies adding all inputs as a logged in admin user """
    print("\nTest: test_add_all_input_devices_logged_in_as_admin")
    login_user(testapp, 'admin', '53CR3t_p4zZW0rD')

    # Add All Inputs
    input_count = 0

    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    choices_input = []
    for each_input in list_inputs_sorted:
        if 'interfaces' not in dict_inputs[each_input]:
            choices_input.append('{inp},'.format(inp=each_input))
        else:
            for each_interface in dict_inputs[each_input]['interfaces']:
                choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface))

    for index, each_input in enumerate(choices_input):
        choice_name = each_input.split(',')[0]
        print("test_add_all_input_devices_logged_in_as_admin: Adding, saving, and deleting Input ({}/{}): {}".format(
            index + 1, len(choices_input), each_input))
        response = add_data(testapp, input_type=each_input)
        assert 'data' in response.json
        assert 'messages' in response.json['data']
        assert 'error' in response.json['data']['messages']
        assert response.json['data']['messages']['error'] == []
        assert 'success' in response.json['data']['messages']
        assert len(response.json['data']['messages']['success']) == 1

        # Verify data was entered into the database
        input_count += 1
        assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(
            Input.query.count(), input_count)

        input_dev = Input.query.filter(Input.id == input_count).first()
        assert choice_name == input_dev.device, "Input name doesn't match: {}".format(choice_name)

        # Save input
        response = save_data(testapp, 'input', device_dev=input_dev)
        assert 'data' in response.json
        assert 'messages' in response.json['data']
        assert 'error' in response.json['data']['messages']
        assert response.json['data']['messages']['error'] == []
        assert 'success' in response.json['data']['messages']
        assert len(response.json['data']['messages']['success']) == 1

        # Delete input (speeds up further input addition checking)
        response = delete_data(testapp, 'input', device_dev=input_dev)
        assert 'data' in response.json
        assert 'messages' in response.json['data']
        assert 'error' in response.json['data']['messages']
        assert response.json['data']['messages']['error'] == []
        assert 'success' in response.json['data']['messages']
        assert len(response.json['data']['messages']['success']) == 1
        input_count -= 1
        assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(
            Input.query.count(), input_count)
コード例 #4
0
def test_add_all_data_devices_logged_in_as_admin(_, testapp):
    """ Verifies adding all inputs as a logged in admin user """
    login_user(testapp, 'admin', '53CR3t_p4zZW0rD')

    # Add All Inputs
    input_count = 0

    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    choices_input = []
    for each_input in list_inputs_sorted:
        if 'interfaces' not in dict_inputs[each_input]:
            choices_input.append('{inp},'.format(inp=each_input))
        else:
            for each_interface in dict_inputs[each_input]['interfaces']:
                choices_input.append('{inp},{int}'.format(inp=each_input,
                                                          int=each_interface))

    for each_input in choices_input:
        choice_name = each_input.split(',')[0]
        print("Testing {}".format(each_input))
        response = add_data(testapp, data_type='input', input_type=each_input)

        # Verify success message flashed
        assert "{} Input with ID".format(choice_name) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        input_count += 1
        assert Input.query.count(
        ) == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(
            Input.query.count(), input_count)

        input_dev = Input.query.filter(Input.id == input_count).first()
        assert dict_inputs[choice_name][
            'input_name'] in input_dev.name, "Input name doesn't match: {}".format(
                choice_name)

    # Add All Maths
    math_count = 0
    for each_math in MATH_INFO.keys():
        response = add_data(testapp, data_type='math', input_type=each_math)

        # Verify success message flashed
        assert "{} Math with ID".format(each_math) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        math_count += 1
        actual_count = Math.query.count()
        assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format(
            actual_count, math_count)

        math_dev = Math.query.filter(Math.id == math_count).first()
        assert each_math in math_dev.math_type, "Math type doesn't match: {}".format(
            each_math)
コード例 #5
0
ファイル: test_endpoints.py プロジェクト: ciscomonkey/Mycodo
def test_add_all_data_devices_logged_in_as_admin(_, testapp):
    """ Verifies adding all inputs as a logged in admin user """
    login_user(testapp, 'admin', '53CR3t_p4zZW0rD')

    # Add All Inputs
    input_count = 0

    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    choices_input = []
    for each_input in list_inputs_sorted:
        if 'interfaces' not in dict_inputs[each_input]:
            choices_input.append('{inp},'.format(inp=each_input))
        else:
            for each_interface in dict_inputs[each_input]['interfaces']:
                choices_input.append('{inp},{int}'.format(inp=each_input, int=each_interface))

    for each_input in choices_input:
        choice_name = each_input.split(',')[0]
        print("Testing {}".format(each_input))
        response = add_data(testapp, data_type='input', input_type=each_input)

        # Verify success message flashed
        assert "{} Input with ID".format(choice_name) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        input_count += 1
        assert Input.query.count() == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(Input.query.count(), input_count)

        input_dev = Input.query.filter(Input.id == input_count).first()
        assert dict_inputs[choice_name]['input_name'] in input_dev.name, "Input name doesn't match: {}".format(choice_name)

    # Add All Maths
    math_count = 0
    for each_math in MATH_INFO.keys():
        response = add_data(testapp, data_type='math', input_type=each_math)

        # Verify success message flashed
        assert "{} Math with ID".format(each_math) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        math_count += 1
        actual_count = Math.query.count()
        assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format(actual_count, math_count)

        math_dev = Math.query.filter(Math.id == math_count).first()
        assert each_math in math_dev.math_type, "Math type doesn't match: {}".format(each_math)
コード例 #6
0
def setup_atlas_flow():
    """
    Step-by-step tool for calibrating the Atlas Scientific RGB sensor
    """
    if not utils_general.user_has_permission('edit_controllers'):
        return redirect(url_for('routes_general.home'))

    form_flow_calibrate = forms_calibration.CalibrationAtlasFlow()

    input_dev = Input.query.filter(Input.device == 'ATLAS_FLOW').all()

    ui_stage = 'start'
    selected_input = None
    input_device_name = None
    complete_with_error = None

    # Begin calibration from Selected input
    if form_flow_calibrate.clear_calibration.data:
        selected_input = Input.query.filter_by(
            unique_id=form_flow_calibrate.selected_input_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        if not selected_input:
            flash(
                'Input not found: {}'.format(
                    form_flow_calibrate.selected_input_id.data), 'error')
        else:
            for each_input in list_inputs_sorted:
                if selected_input.device == each_input[0]:
                    input_device_name = each_input[1]
        if selected_input.is_activated:
            control = DaemonControl()
            return_status, return_string = control.input_atlas_flow_clear_total_volume(
                selected_input.unique_id)
        else:
            atlas_command = AtlasScientificCommand(selected_input)
            return_status, return_string = atlas_command.send_command('Clear')
        if return_status:
            complete_with_error = return_string
        ui_stage = 'complete'

    return render_template('tools/calibration_options/atlas_flow.html',
                           complete_with_error=complete_with_error,
                           form_flow_calibrate=form_flow_calibrate,
                           input=input_dev,
                           input_device_name=input_device_name,
                           selected_input=selected_input,
                           ui_stage=ui_stage)
コード例 #7
0
def setup_atlas_ph():
    """
    Step-by-step tool for calibrating the Atlas Scientific pH sensor
    """
    if not utils_general.user_has_permission('edit_controllers'):
        return redirect(url_for('routes_general.home'))

    form_ph_calibrate = forms_calibration.CalibrationAtlasph()

    input_dev = Input.query.filter(Input.device == 'ATLAS_PH').all()

    ui_stage = 'start'
    backend_stage = None
    next_stage = None
    selected_input = None
    selected_point_calibration = None
    input_device_name = None
    complete_with_error = None

    if form_ph_calibrate.hidden_current_stage.data:
        backend_stage = form_ph_calibrate.hidden_current_stage.data

    if form_ph_calibrate.hidden_selected_point_calibration.data:
        selected_point_calibration = form_ph_calibrate.hidden_selected_point_calibration.data
    elif form_ph_calibrate.point_calibration.data:
        selected_point_calibration = form_ph_calibrate.point_calibration.data

    if selected_point_calibration:
        list_point_calibrations = selected_point_calibration.split(',')
    else:
        list_point_calibrations = []

    # Clear Calibration memory
    if form_ph_calibrate.clear_calibration.data:
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.selected_input_id.data).first()
        atlas_command = AtlasScientificCommand(selected_input)
        status, message = atlas_command.calibrate('clear_calibration')

        sensor_measurement = atlas_command.get_sensor_measurement()

        if isinstance(message, tuple):
            message_status = message[0]
            message_info = message[1]
            message = "Calibration command returned from sensor: {}".format(
                message_status)
            if message_info:
                message += ": {}".format(message_info)
        else:
            message = "Calibration command returned from sensor: {}".format(
                message)

        if sensor_measurement != 'NA':
            message = "{} {}".format(sensor_measurement, message)

        if status:
            flash(message, "error")
        else:
            flash(message, "success")

    # Begin calibration from Selected input
    elif form_ph_calibrate.start_calibration.data:
        ui_stage = 'temperature'
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.selected_input_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        if not selected_input:
            flash(
                'Input not found: {}'.format(
                    form_ph_calibrate.selected_input_id.data), 'error')
        else:
            for each_input in list_inputs_sorted:
                if selected_input.device == each_input[0]:
                    input_device_name = each_input[1]

    # Continue calibration from selected input
    elif (form_ph_calibrate.go_to_next_stage.data
          or form_ph_calibrate.go_to_last_stage.data
          or (backend_stage is not None
              and backend_stage not in ['start', 'temperature'])):
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.hidden_input_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        for each_input in list_inputs_sorted:
            if selected_input.device == each_input[0]:
                input_device_name = each_input[1]

    if backend_stage in ['temperature', 'low', 'mid', 'high']:
        time.sleep(2)  # Sleep makes querying sensor more stable

        # Determine next ui_stage
        if backend_stage == 'temperature':
            next_stage = list_point_calibrations[0]
            logger.error("next_stage: {}".format(next_stage))
        else:
            current_stage_index = list_point_calibrations.index(backend_stage)
            if current_stage_index == len(list_point_calibrations) - 1:
                next_stage = 'complete'
            else:
                next_stage = list_point_calibrations[current_stage_index + 1]

    if form_ph_calibrate.clear_calibration.data:
        pass
    elif backend_stage == 'temperature':
        if form_ph_calibrate.temperature.data is None:
            flash(
                gettext(
                    "A valid temperature is required: %(temp)s is invalid.",
                    temp=form_ph_calibrate.temperature.data), "error")
            ui_stage = 'start'
        else:
            temp = '{temp:.2f}'.format(
                temp=float(form_ph_calibrate.temperature.data))
            ui_stage, complete_with_error = dual_commands_to_sensor(
                selected_input,
                'temperature',
                temp,
                'continuous',
                current_stage='temperature',
                next_stage=next_stage)
    elif backend_stage == 'low':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'low',
            '4.0',
            'continuous',
            current_stage='low',
            next_stage=next_stage)
    elif backend_stage == 'mid':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'mid',
            '7.0',
            'continuous',
            current_stage='mid',
            next_stage=next_stage)
    elif backend_stage == 'high':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'high',
            '10.0',
            'end',
            current_stage='high',
            next_stage=next_stage)

    return render_template(
        'tools/calibration_options/atlas_ph.html',
        complete_with_error=complete_with_error,
        form_ph_calibrate=form_ph_calibrate,
        input=input_dev,
        input_device_name=input_device_name,
        selected_input=selected_input,
        selected_point_calibration=selected_point_calibration,
        ui_stage=ui_stage)
コード例 #8
0
def setup_atlas_ec():
    """
    Step-by-step tool for calibrating the Atlas Scientific EC sensor
    """
    if not utils_general.user_has_permission('edit_controllers'):
        return redirect(url_for('routes_general.home'))

    form_ec_calibrate = forms_calibration.CalibrationAtlasEC()

    input_dev = Input.query.filter(Input.device == 'ATLAS_EC').all()

    ui_stage = 'start'
    backend_stage = None
    next_stage = None
    selected_input = None
    selected_point_calibration = None
    input_device_name = None
    complete_with_error = None

    if form_ec_calibrate.hidden_current_stage.data:
        backend_stage = form_ec_calibrate.hidden_current_stage.data

    if form_ec_calibrate.hidden_selected_point_calibration.data:
        selected_point_calibration = form_ec_calibrate.hidden_selected_point_calibration.data
    elif form_ec_calibrate.point_calibration.data:
        selected_point_calibration = form_ec_calibrate.point_calibration.data

    if selected_point_calibration:
        list_point_calibrations = selected_point_calibration.split(',')
    else:
        list_point_calibrations = []

    if form_ec_calibrate.point_low_uS.data:
        point_low_uS = form_ec_calibrate.point_low_uS.data
    else:
        point_low_uS = form_ec_calibrate.hidden_point_low_uS.data

    if form_ec_calibrate.point_high_uS.data:
        point_high_uS = form_ec_calibrate.point_high_uS.data
    else:
        point_high_uS = form_ec_calibrate.hidden_point_high_uS.data

    # Begin calibration from Selected input
    if form_ec_calibrate.start_calibration.data:
        ui_stage = 'point_enter_uS'
        selected_input = Input.query.filter_by(
            unique_id=form_ec_calibrate.selected_input_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        if not selected_input:
            flash(
                'Input not found: {}'.format(
                    form_ec_calibrate.selected_input_id.data), 'error')
        else:
            for each_input in list_inputs_sorted:
                if selected_input.device == each_input[0]:
                    input_device_name = each_input[1]

    # Continue calibration from selected input
    elif (form_ec_calibrate.go_to_next_stage.data
          or form_ec_calibrate.go_to_last_stage.data
          or (backend_stage is not None
              and backend_stage not in ['start', 'point_enter_uS'])):
        selected_input = Input.query.filter_by(
            unique_id=form_ec_calibrate.hidden_input_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        for each_input in list_inputs_sorted:
            if selected_input.device == each_input[0]:
                input_device_name = each_input[1]

    if backend_stage in ['point_enter_uS', 'dry', 'low', 'high']:
        time.sleep(2)  # Sleep makes querying sensor more stable

        # Determine next ui_stage
        if backend_stage == 'point_enter_uS':
            next_stage = 'dry'
            logger.error("next_stage: {}".format(next_stage))
        elif backend_stage == 'dry':
            next_stage = list_point_calibrations[0]
            logger.error("next_stage: {}".format(next_stage))
        else:
            current_stage_index = list_point_calibrations.index(backend_stage)
            if current_stage_index == len(list_point_calibrations) - 1:
                next_stage = 'complete'
            else:
                next_stage = list_point_calibrations[current_stage_index + 1]

    if backend_stage == 'point_enter_uS':
        ui_stage = next_stage
        complete_with_error = None
    elif backend_stage == 'dry':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'ec_dry',
            None,
            'continuous',
            current_stage='dry',
            next_stage=next_stage)
    elif backend_stage == 'low':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'ec_low',
            point_low_uS,
            'continuous',
            current_stage='low',
            next_stage=next_stage)
    elif backend_stage == 'high':
        ui_stage, complete_with_error = dual_commands_to_sensor(
            selected_input,
            'ec_high',
            point_high_uS,
            'end',
            current_stage='high',
            next_stage=next_stage)

    return render_template(
        'tools/calibration_options/atlas_ec.html',
        complete_with_error=complete_with_error,
        form_ec_calibrate=form_ec_calibrate,
        input=input_dev,
        input_device_name=input_device_name,
        point_high_uS=point_high_uS,
        point_low_uS=point_low_uS,
        selected_input=selected_input,
        selected_point_calibration=selected_point_calibration,
        ui_stage=ui_stage)
コード例 #9
0
def test_add_all_data_devices_logged_in_as_admin(_, testapp):
    """ Verifies adding all inputs as a logged in admin user """
    print("\nTest: test_add_all_data_devices_logged_in_as_admin")
    login_user(testapp, 'admin', '53CR3t_p4zZW0rD')

    # Add All Inputs
    input_count = 0

    dict_inputs = parse_input_information()
    list_inputs_sorted = generate_form_input_list(dict_inputs)

    choices_input = []
    for each_input in list_inputs_sorted:
        if 'interfaces' not in dict_inputs[each_input]:
            choices_input.append('{inp},'.format(inp=each_input))
        else:
            for each_interface in dict_inputs[each_input]['interfaces']:
                choices_input.append('{inp},{int}'.format(inp=each_input,
                                                          int=each_interface))

    for index, each_input in enumerate(choices_input):
        choice_name = each_input.split(',')[0]
        print(
            "test_add_all_data_devices_logged_in_as_admin: Adding and deleting Input ({}/{}): {}"
            .format(index + 1, len(choices_input), each_input))
        response = add_data(testapp, data_type='input', input_type=each_input)

        # Verify success message flashed
        assert "{} Input with ID".format(choice_name) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        input_count += 1
        assert Input.query.count(
        ) == input_count, "Number of Inputs doesn't match: In DB {}, Should be: {}".format(
            Input.query.count(), input_count)

        input_dev = Input.query.filter(Input.id == input_count).first()
        assert choice_name == input_dev.device, "Input name doesn't match: {}".format(
            choice_name)

        # Delete input (speeds up further input addition checking)
        response = delete_data(testapp,
                               data_type='input',
                               device_dev=input_dev)
        assert "Delete input with ID: {}".format(
            input_dev.unique_id) in response
        input_count -= 1

    # Add All Maths
    math_count = 0
    for index, each_math in enumerate(MATH_INFO.keys()):
        print(
            "test_add_all_data_devices_logged_in_as_admin: Adding Math ({}/{}): {}"
            .format(index + 1, len(MATH_INFO.keys()), each_math))
        response = add_data(testapp, data_type='math', input_type=each_math)

        # Verify success message flashed
        assert "{} Math with ID".format(each_math) in response
        assert "successfully added" in response

        # Verify data was entered into the database
        math_count += 1
        actual_count = Math.query.count()
        assert actual_count == math_count, "Number of Maths don't match: In DB {}, Should be: {}".format(
            actual_count, math_count)

        math_dev = Math.query.filter(Math.id == math_count).first()
        assert each_math in math_dev.math_type, "Math type doesn't match: {}".format(
            each_math)

        # Delete input (speeds up further input addition checking)
        response = delete_data(testapp, data_type='math', device_dev=math_dev)
        assert "Delete math with ID: {}".format(math_dev.unique_id) in response
        math_count -= 1
コード例 #10
0
def setup_atlas_ph():
    """
    Step-by-step tool for calibrating the Atlas Scientific pH sensor
    """
    if not utils_general.user_has_permission('edit_controllers'):
        return redirect(url_for('routes_general.home'))

    form_ph_calibrate = forms_calibration.CalibrationAtlasph()

    input_dev = Input.query.filter(
        or_(Input.device == 'ATLAS_PH_UART',
            Input.device == 'ATLAS_PH_I2C')).all()
    stage = 0
    next_stage = None
    selected_input = None
    input_device_name = None
    complete_with_error = None

    if form_ph_calibrate.hidden_next_stage.data is not None:
        next_stage = int(form_ph_calibrate.hidden_next_stage.data)

    # Clear Calibration memory
    if form_ph_calibrate.clear_calibration.data:
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.selected_sensor_id.data).first()
        atlas_command = AtlasScientificCommand(selected_input)
        status, message = atlas_command.calibrate('clear_calibration')
        if status:
            flash(message, "error")
        else:
            flash(message, "success")

    # Begin calibration from Selected input
    elif form_ph_calibrate.go_from_first_stage.data:
        stage = 1
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.selected_sensor_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        if not selected_input:
            flash(
                'Input not found: {}'.format(
                    form_ph_calibrate.selected_sensor_id.data), 'error')
        else:
            for each_input in list_inputs_sorted:
                if selected_input.device == each_input[0]:
                    input_device_name = each_input[1]

    # Continue calibration from selected input
    elif (form_ph_calibrate.go_to_next_stage.data
          or form_ph_calibrate.go_to_last_stage.data
          or (next_stage is not None and next_stage > 1)):
        selected_input = Input.query.filter_by(
            unique_id=form_ph_calibrate.hidden_sensor_id.data).first()
        dict_inputs = parse_input_information()
        list_inputs_sorted = generate_form_input_list(dict_inputs)
        for each_input in list_inputs_sorted:
            if selected_input.device == each_input[0]:
                input_device_name = each_input[1]

    if next_stage == 2:
        if form_ph_calibrate.temperature.data is None:
            flash(
                gettext(
                    "A valid temperature is required: %(temp)s is invalid.",
                    temp=form_ph_calibrate.temperature.data), "error")
            stage = 1
        else:
            temp = '{temp:.2f}'.format(temp=form_ph_calibrate.temperature.data)
            stage, complete_with_error = dual_commands_to_sensor(
                selected_input, 'temperature', temp, 'continuous', 1)
    elif next_stage == 3:
        stage, complete_with_error = dual_commands_to_sensor(
            selected_input, 'mid', '7.0', 'continuous', 2)
    elif next_stage == 4:
        stage, complete_with_error = dual_commands_to_sensor(
            selected_input, 'low', '4.0', 'continuous', 3)
    elif next_stage == 5:
        stage, complete_with_error = dual_commands_to_sensor(
            selected_input, 'high', '10.0', 'end', 4)

    return render_template('tools/calibration_options/atlas_ph.html',
                           complete_with_error=complete_with_error,
                           form_ph_calibrate=form_ph_calibrate,
                           sensor=input_dev,
                           sensor_device_name=input_device_name,
                           selected_sensor=selected_input,
                           stage=stage)