Пример #1
0
def page_relay():
    """ Display relay status and config """
    if not logged_in():
        return redirect(url_for('general_routes.home'))

    lcd = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], LCD, entry='all')
    relay = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], Relay, entry='all')
    relayconditional = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], RelayConditional, entry='all')
    users = db_retrieve_table(
        current_app.config['USER_DB_PATH'], Users, entry='all')

    display_order_unsplit = db_retrieve_table(
        current_app.config['MYCODO_DB_PATH'], DisplayOrder, entry='first').relay
    if display_order_unsplit:
        display_order = display_order_unsplit.split(",")
    else:
        display_order = []

    form_add_relay = flaskforms.AddRelay()
    form_del_relay = flaskforms.DelRelay()
    form_mod_relay = flaskforms.ModRelay()
    form_order_relay = flaskforms.OrderRelay()
    form_relay_on_off = flaskforms.RelayOnOff()
    form_add_relay_cond = flaskforms.AddRelayConditional()
    form_mod_relay_cond = flaskforms.ModRelayConditional()

    if request.method == 'POST':
        form_name = request.form['form-name']
        if form_name == 'RelayOnOff':
            flaskutils.relay_on_off(form_relay_on_off)
        elif form_name == 'addRelay':
            flaskutils.relay_add(form_add_relay, display_order)
        elif form_name == 'modRelay':
            flaskutils.relay_mod(form_mod_relay)
        elif form_name == 'delRelay':
            flaskutils.relay_del(form_del_relay, display_order)
        elif form_name == 'orderRelay':
            flaskutils.relay_reorder(form_order_relay, display_order)
        elif form_name == 'addRelayConditional':
            flaskutils.relay_conditional_add(form_add_relay_cond)
        elif form_name == 'modRelayConditional':
            flaskutils.relay_conditional_mod(form_mod_relay_cond)
        return redirect('/relay')

    return render_template('pages/relay.html',
                           lcd=lcd,
                           relay=relay,
                           relayconditional=relayconditional,
                           users=users,
                           displayOrder=display_order,
                           form_order_relay=form_order_relay,
                           form_add_relay=form_add_relay,
                           form_mod_relay=form_mod_relay,
                           form_del_relay=form_del_relay,
                           form_relay_on_off=form_relay_on_off,
                           form_add_relay_cond=form_add_relay_cond,
                           form_mod_relay_cond=form_mod_relay_cond)
Пример #2
0
def page_output():
    """ Display relay status and config """
    camera = Camera.query.all()
    lcd = LCD.query.all()
    relay = Relay.query.all()
    user = User.query.all()

    conditional = Conditional.query.filter(
        Conditional.conditional_type == 'relay').all()
    conditional_actions = ConditionalActions.query.all()

    display_order = csv_to_list_of_int(DisplayOrder.query.first().relay)

    form_add_relay = flaskforms.RelayAdd()
    form_mod_relay = flaskforms.RelayMod()

    form_conditional = flaskforms.Conditional()
    form_conditional_actions = flaskforms.ConditionalActions()

    # Create list of file names from the output_options directory
    # Used in generating the correct options for each relay/device
    relay_templates = []
    relay_path = os.path.join(
        INSTALL_DIRECTORY,
        'mycodo/mycodo_flask/templates/pages/output_options')
    for (_, _, file_names) in os.walk(relay_path):
        relay_templates.extend(file_names)
        break

    if request.method == 'POST':
        if not flaskutils.user_has_permission('edit_controllers'):
            return redirect(url_for('page_routes.page_output'))

        if form_add_relay.relay_add.data:
            flaskutils.relay_add(form_add_relay)
        elif form_mod_relay.save.data:
            flaskutils.relay_mod(form_mod_relay)
        elif (form_mod_relay.turn_on.data or form_mod_relay.turn_off.data
              or form_mod_relay.on_submit.data):
            flaskutils.relay_on_off(form_mod_relay)
        elif form_mod_relay.delete.data:
            flaskutils.relay_del(form_mod_relay)
        elif form_mod_relay.order_up.data:
            flaskutils.relay_reorder(form_mod_relay.relay_id.data,
                                     display_order, 'up')
        elif form_mod_relay.order_down.data:
            flaskutils.relay_reorder(form_mod_relay.relay_id.data,
                                     display_order, 'down')
        elif form_conditional.add_cond.data:
            flaskutils.conditional_add(form_conditional.conditional_type.data,
                                       form_conditional.quantity.data)
        elif form_conditional.delete_cond.data:
            flaskutils.conditional_mod(form_conditional, 'delete')
        elif form_conditional.save_cond.data:
            flaskutils.conditional_mod(form_conditional, 'modify')
        elif form_conditional.activate_cond.data:
            flaskutils.conditional_activate(form_conditional)
        elif form_conditional.deactivate_cond.data:
            flaskutils.conditional_deactivate(form_conditional)
        elif form_conditional_actions.add_action.data:
            flaskutils.conditional_action_add(form_conditional_actions)
        elif form_conditional_actions.save_action.data:
            flaskutils.conditional_action_mod(form_conditional_actions,
                                              'modify')
        elif form_conditional_actions.delete_action.data:
            flaskutils.conditional_action_mod(form_conditional_actions,
                                              'delete')
        return redirect(url_for('page_routes.page_output'))

    return render_template('pages/output.html',
                           camera=camera,
                           conditional=conditional,
                           conditional_actions=conditional_actions,
                           conditional_actions_list=CONDITIONAL_ACTIONS,
                           displayOrder=display_order,
                           form_conditional=form_conditional,
                           form_conditional_actions=form_conditional_actions,
                           form_add_relay=form_add_relay,
                           form_mod_relay=form_mod_relay,
                           lcd=lcd,
                           relay=relay,
                           relay_templates=relay_templates,
                           user=user)
Пример #3
0
def page_relay():
    """ Display relay status and config """
    camera = Camera.query.all()
    lcd = LCD.query.all()
    relay = Relay.query.all()
    user = User.query.all()

    conditional = Conditional.query.filter(
        Conditional.conditional_type == 'relay').all()
    conditional_actions = ConditionalActions.query.all()

    display_order = csv_to_list_of_int(DisplayOrder.query.first().relay)

    form_add_relay = flaskforms.RelayAdd()
    form_mod_relay = flaskforms.RelayMod()

    form_conditional = flaskforms.Conditional()
    form_conditional_actions = flaskforms.ConditionalActions()

    if request.method == 'POST':
        if not flaskutils.user_has_permission('edit_controllers'):
            return redirect(url_for('general_routes.page_relay'))

        if form_add_relay.relay_add.data:
            flaskutils.relay_add(form_add_relay)
        elif form_mod_relay.save.data:
            flaskutils.relay_mod(form_mod_relay)
        elif (form_mod_relay.turn_on.data or
                form_mod_relay.turn_off.data or
                form_mod_relay.sec_on_submit.data):
            flaskutils.relay_on_off(form_mod_relay)
        elif form_mod_relay.delete.data:
            flaskutils.relay_del(form_mod_relay)
        elif form_mod_relay.order_up.data:
            flaskutils.relay_reorder(form_mod_relay.relay_id.data,
                                     display_order, 'up')
        elif form_mod_relay.order_down.data:
            flaskutils.relay_reorder(form_mod_relay.relay_id.data,
                                     display_order, 'down')
        elif form_conditional.add_cond.data:
            flaskutils.conditional_add(form_conditional.conditional_type.data,
                                       form_conditional.quantity.data)
        elif form_conditional.delete_cond.data:
            flaskutils.conditional_mod(form_conditional, 'delete')
        elif form_conditional.save_cond.data:
            flaskutils.conditional_mod(form_conditional, 'modify')
        elif form_conditional.activate_cond.data:
            flaskutils.conditional_activate(form_conditional)
        elif form_conditional.deactivate_cond.data:
            flaskutils.conditional_deactivate(form_conditional)
        elif form_conditional_actions.add_action.data:
            flaskutils.conditional_action_add(form_conditional_actions)
        elif form_conditional_actions.save_action.data:
            flaskutils.conditional_action_mod(form_conditional_actions,
                                              'modify')
        elif form_conditional_actions.delete_action.data:
            flaskutils.conditional_action_mod(form_conditional_actions,
                                              'delete')
        return redirect('/relay')

    return render_template('pages/relay.html',
                           camera=camera,
                           conditional=conditional,
                           conditional_actions=conditional_actions,
                           conditional_actions_list=CONDITIONAL_ACTIONS,
                           displayOrder=display_order,
                           form_conditional=form_conditional,
                           form_conditional_actions=form_conditional_actions,
                           form_add_relay=form_add_relay,
                           form_mod_relay=form_mod_relay,
                           lcd=lcd,
                           relay=relay,
                           user=user)