Пример #1
0
def trigger_activate(trigger_id):
    """Activate a Trigger"""
    error = []
    action = '{action} {controller}'.format(
        action=TRANSLATIONS['activate']['title'],
        controller=TRANSLATIONS['trigger']['title'])

    mod_trigger = Trigger.query.filter(Trigger.unique_id == trigger_id).first()

    # Check for errors in the Trigger settings
    if mod_trigger.trigger_type == 'edge':
        error = check_cond_edge(mod_trigger, error)
    elif mod_trigger.trigger_type == 'output':
        error = check_cond_output(mod_trigger, error)

    actions = Actions.query.filter(Actions.function_id == trigger_id)

    if not actions.count():
        error.append(
            "No Actions found: Add at least one Action before activating.")

    for each_action in actions.all():
        error = check_actions(each_action, error)

    if mod_trigger.trigger_type == 'run_pwm_method':
        mod_trigger_ready = Trigger.query.filter(
            Trigger.unique_id == trigger_id).first()
        mod_trigger_ready.method_start_time = 'Ready'
        db.session.commit()

    if not error:
        controller_activate_deactivate('activate', 'Trigger', trigger_id)

    flash_success_errors(error, action, url_for('routes_page.page_function'))
Пример #2
0
def conditional_activate(cond_id):
    """Activate a Conditional"""
    error = []
    action = '{action} {controller}'.format(
        action=TRANSLATIONS['activate']['title'],
        controller=TRANSLATIONS['conditional']['title'])

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id).all()

    for each_condition in conditions:
        # Check for errors in the Conditional settings
        error = check_cond_measurements(each_condition, error)

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id)
    if not conditions.count():
        error.append(
            "No Conditions found: Add at least one Condition before activating."
        )

    actions = Actions.query.filter(Actions.function_id == cond_id)
    if not actions.count():
        error.append(
            "No Actions found: Add at least one Action before activating.")

    for each_action in actions.all():
        error = check_actions(each_action, error)

    if not error:
        controller_activate_deactivate('activate', 'Conditional', cond_id)

    flash_success_errors(error, action, url_for('routes_page.page_function'))
Пример #3
0
def trigger_activate(trigger_id):
    """Activate a Trigger"""
    messages = {"success": [], "info": [], "warning": [], "error": []}

    mod_trigger = Trigger.query.filter(Trigger.unique_id == trigger_id).first()

    # Check for errors in the Trigger settings
    if mod_trigger.trigger_type == 'edge':
        messages["error"] = check_cond_edge(mod_trigger, messages["error"])
    elif mod_trigger.trigger_type == 'output':
        messages["error"] = check_cond_output(mod_trigger, messages["error"])

    actions = Actions.query.filter(Actions.function_id == trigger_id)

    if not actions.count(
    ) and mod_trigger.trigger_type != 'trigger_run_pwm_method':
        messages["error"].append(
            "No Actions found: Add at least one Action before activating.")

    for each_action in actions.all():
        messages["error"] = check_actions(each_action, messages["error"])

    if not messages["error"]:
        controller_activate_deactivate('activate',
                                       'Trigger',
                                       trigger_id,
                                       flash_message=False)
        messages["success"].append('{action} {controller}'.format(
            action=TRANSLATIONS['activate']['title'],
            controller=TRANSLATIONS['trigger']['title']))

    return messages
Пример #4
0
def conditional_activate(cond_id):
    """Activate a Conditional"""
    error = []
    action = '{action} {controller}'.format(
        action=TRANSLATIONS['activate']['title'],
        controller=TRANSLATIONS['conditional']['title'])

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id).all()

    for each_condition in conditions:
        # Check for errors in the Conditional settings
        error = check_cond_measurements(each_condition, error)

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id)
    if not conditions.count():
        error.append("No Conditions found: Add at least one Condition before activating.")

    actions = Actions.query.filter(
        Actions.function_id == cond_id)
    if not actions.count():
        error.append("No Actions found: Add at least one Action before activating.")

    for each_action in actions.all():
        error = check_actions(each_action, error)

    if not error:
        controller_activate_deactivate('activate', 'Conditional', cond_id)

    flash_success_errors(error, action, url_for('routes_page.page_function'))
Пример #5
0
def conditional_activate(cond_id):
    """Activate a Conditional"""
    messages = {
        "success": [],
        "info": [],
        "warning": [],
        "error": []
    }

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id).all()

    for each_condition in conditions:
        # Check for errors in the Conditional settings
        messages["success"] = check_cond_conditions(
            each_condition, messages["success"])

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id)
    if not conditions.count():
        messages["info"].append(
            "Conditional activated without any Conditions. Typical "
            "Conditional Controller use involves the use of Conditions. Only "
            "proceed without Conditions if you know what you're doing.")

    actions = Actions.query.filter(Actions.function_id == cond_id)
    if not actions.count():
        messages["info"].append(
            "Conditional activated without any Actions. Typical "
            "Conditional Controller use involves the use of Actions. Only "
            "proceed without Actions if you know what you're doing.")

    for each_action in actions.all():
        messages["success"] = check_actions(each_action, messages["success"])

    messages = controller_activate_deactivate(
        messages, 'activate', 'Conditional', cond_id, flash_message=False)

    if not messages["success"]:
        messages["success"].append('{action} {controller}'.format(
            action=TRANSLATIONS['activate']['title'],
            controller=TRANSLATIONS['conditional']['title']))

    return messages
Пример #6
0
def conditional_activate(cond_id):
    """Activate a Conditional"""
    error = []
    action = '{action} {controller}'.format(
        action=TRANSLATIONS['activate']['title'],
        controller=TRANSLATIONS['conditional']['title'])

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id).all()

    for each_condition in conditions:
        # Check for errors in the Conditional settings
        error = check_cond_conditions(each_condition, error)

    conditions = ConditionalConditions.query.filter(
        ConditionalConditions.conditional_id == cond_id)
    if not conditions.count():
        flash(
            "Conditional activated without any Conditions. Typical "
            "Conditional Controller use involves the use of Conditions. Only "
            "proceed without Conditions if you know what you're doing.",
            'info')

    actions = Actions.query.filter(
        Actions.function_id == cond_id)
    if not actions.count():
        flash(
            "Conditional activated without any Actions. Typical "
            "Conditional Controller use involves the use of Actions. Only "
            "proceed without Actions if you know what you're doing.",
            'info')

    for each_action in actions.all():
        error = check_actions(each_action, error)

    if not error:
        controller_activate_deactivate('activate', 'Conditional', cond_id)

    flash_success_errors(error, action, url_for('routes_page.page_function'))
Пример #7
0
def trigger_activate(trigger_id):
    """Activate a Trigger"""
    error = []
    action = '{action} {controller}'.format(
        action=TRANSLATIONS['activate']['title'],
        controller=TRANSLATIONS['trigger']['title'])

    mod_trigger = Trigger.query.filter(
        Trigger.unique_id == trigger_id).first()

    # Check for errors in the Trigger settings
    if mod_trigger.trigger_type == 'edge':
        error = check_cond_edge(mod_trigger, error)
    elif mod_trigger.trigger_type == 'output':
        error = check_cond_output(mod_trigger, error)

    actions = Actions.query.filter(
        Actions.function_id == trigger_id)

    if not actions.count():
        error.append("No Actions found: Add at least one Action before activating.")

    for each_action in actions.all():
        error = check_actions(each_action, error)

    if mod_trigger.trigger_type == 'run_pwm_method':
        mod_trigger_ready = Trigger.query.filter(
            Trigger.unique_id == trigger_id).first()
        mod_trigger_ready.method_start_time = 'Ready'
        db.session.commit()

    if not error:
        controller_activate_deactivate(
            'activate',
            'Trigger',
            trigger_id)

    flash_success_errors(error, action, url_for('routes_page.page_function'))