Ejemplo n.º 1
0
def power_schedule(id):
    zone = f'power{id}'
    log.debug(f'power_schedule() called with powerzone: {zone}')
    job1_enabled = (neptune.get_schedule_by_zone_job(zone, '1')[0][3])
    job2_enabled = (neptune.get_schedule_by_zone_job(zone, '2')[0][3])
    return render_template('power_schedule.html', id=id,
                           job1_enabled = job1_enabled,
                           job2_enabled = job2_enabled)
Ejemplo n.º 2
0
def zone(id):
    zone = f'zone{id}'
    log.debug(f'zone() called with zone: {zone}')
    any_zones_running = neptune.any_zones_running('water')
    is_zone_enabled = neptune.zone_enabled(zone)
    is_zone_running = neptune.is_this_zone_running(zone)
    is_zone_running_manually = neptune.is_this_zone_running_manually(zone)
    job1_enabled = (neptune.get_schedule_by_zone_job(zone, '1')[0][3])
    job2_enabled = (neptune.get_schedule_by_zone_job(zone, '2')[0][3])
    job1_running = (neptune.get_schedule_by_zone_job(zone, '1')[0][7])
    job2_running = (neptune.get_schedule_by_zone_job(zone, '2')[0][7])
    total_zone_water_usage = water_usage(zone, 'read_total_gallons_used', 0)
    running_current_total_gallons = water_usage(zone,
                                                'read_gallons_current_run', 0)
    current_gpm = neptune.get_current_gpm()
    current_water_source = (neptune.get_water_source()['source_to_use'])
    any_notification_source_available = neptune.notifications(
        'systemwide', 'enabled', 'check')
    notifications_enabled = neptune.notifications(zone, 'notifications',
                                                  'enabled')
    systemwide_notifications_enabled = neptune.notifications(
        'systemwide', 'enabled', 'enabled')
    sms_enabled = neptune.notifications(zone, 'sms', 'enabled')
    pb_enabled = neptune.notifications(zone, 'pb', 'enabled')
    email_enabled = neptune.notifications(zone, 'email', 'enabled')

    if job1_running:
        job_id = (neptune.get_schedule_by_zone_job(zone, '1')[0][0])
    elif job2_running:
        job_id = (neptune.get_schedule_by_zone_job(zone, '2')[0][0])
    else:
        job_id = ''

    return render_template(
        'zone.html',
        zone_enabled=is_zone_enabled,
        is_zone_running=is_zone_running,
        is_zone_running_manually=is_zone_running_manually,
        any_zones_running=any_zones_running,
        job1_enabled=job1_enabled,
        job2_enabled=job2_enabled,
        job1_running=job1_running,
        job2_running=job2_running,
        total_zone_water_usage=total_zone_water_usage,
        running_current_total_gallons=running_current_total_gallons,
        current_gpm=current_gpm,
        current_water_source=current_water_source,
        notifications_enabled=notifications_enabled,
        any_notification_source_available=any_notification_source_available,
        systemwide_notifications_enabled=systemwide_notifications_enabled,
        sms_enabled=sms_enabled,
        email_enabled=email_enabled,
        pb_enabled=pb_enabled,
        job_id=job_id,
        id=id)
Ejemplo n.º 3
0
def power(id):
    zone = f'power{id}'
    log.debug(f'power() called with powerzone: {zone}')
    any_zones_running = neptune.any_zones_running('power')
    is_zone_enabled = neptune.zone_enabled(zone)
    is_zone_running = neptune.is_this_zone_running(zone)
    is_zone_running_manually = neptune.is_this_zone_running_manually(zone)
    job1_enabled = (neptune.get_schedule_by_zone_job(zone, '1')[0][3])
    job2_enabled = (neptune.get_schedule_by_zone_job(zone, '2')[0][3])
    job1_running = (neptune.get_schedule_by_zone_job(zone, '1')[0][7])
    job2_running = (neptune.get_schedule_by_zone_job(zone, '2')[0][7])
    any_notification_source_available = neptune.notifications(
        'systemwide', 'enabled', 'check')
    notifications_enabled = neptune.notifications(zone, 'notifications',
                                                  'enabled')
    systemwide_notifications_enabled = neptune.notifications(
        'systemwide', 'enabled', 'enabled')
    sms_enabled = neptune.notifications(zone, 'sms', 'enabled')
    pb_enabled = neptune.notifications(zone, 'pb', 'enabled')
    email_enabled = neptune.notifications(zone, 'email', 'enabled')

    if job1_running:
        job_id = (neptune.get_schedule_by_zone_job(zone, '1')[0][0])
    elif job2_running:
        job_id = (neptune.get_schedule_by_zone_job(zone, '2')[0][0])
    else:
        job_id = ''

    return render_template(
        'power.html',
        zone_enabled=is_zone_enabled,
        is_zone_running=is_zone_running,
        is_zone_running_manually=is_zone_running_manually,
        any_zones_running=any_zones_running,
        job1_enabled=job1_enabled,
        job2_enabled=job2_enabled,
        job1_running=job1_running,
        job2_running=job2_running,
        job_id=job_id,
        id=id,
        notifications_enabled=notifications_enabled,
        any_notification_source_available=any_notification_source_available,
        systemwide_notifications_enabled=systemwide_notifications_enabled,
        sms_enabled=sms_enabled,
        email_enabled=email_enabled,
        pb_enabled=pb_enabled)
Ejemplo n.º 4
0
def powerschedulejob2(id):
    zone2_with_conflict = ''
    job2_with_conflict = ''
    zone = f'power{id}'
    log.debug(f'powerschedulejob2() called with powerzone: {zone}')
    form = PowerJob2Form()
    job2_jobid = (neptune.get_schedule_by_zone_job(zone, '2')[0][0])
    job2_enabled = (neptune.get_schedule_by_zone_job(zone, '2')[0][3])
    job2_start_time = (neptune.get_schedule_by_zone_job(zone, '2')[0][4])
    job2_duration = (neptune.get_schedule_by_zone_job(zone, '2')[0][6])
    job2_monday = (neptune.get_schedule_by_zone_job(zone, '2')[0][8])
    job2_tuesday = (neptune.get_schedule_by_zone_job(zone, '2')[0][9])
    job2_wednesday = (neptune.get_schedule_by_zone_job(zone, '2')[0][10])
    job2_thursday = (neptune.get_schedule_by_zone_job(zone, '2')[0][11])
    job2_friday = (neptune.get_schedule_by_zone_job(zone, '2')[0][12])
    job2_saturday = (neptune.get_schedule_by_zone_job(zone, '2')[0][13])
    job2_sunday = (neptune.get_schedule_by_zone_job(zone, '2')[0][14])
    form.start_hour_job2.data = str(job2_start_time.hour)
    form.start_minute_job2.data = str(job2_start_time.minute)
    form.duration_job2.data = str(job2_duration)
    form.monday_job2.data = job2_monday
    form.tuesday_job2.data = job2_tuesday
    form.wednesday_job2.data = job2_wednesday
    form.thursday_job2.data = job2_thursday
    form.friday_job2.data = job2_friday
    form.saturday_job2.data = job2_saturday
    form.sunday_job2.data = job2_sunday

    if form.validate_on_submit():
        # Uodate job start/stop times and duration based on form input
        job2_new_start_hour = request.form['start_hour_job2']
        job2_new_start_minute = request.form['start_minute_job2']
        job2_new_start_time = datetime.strptime(
            job2_new_start_hour + ':' + job2_new_start_minute + ':00',
            '%H:%M:%S').time()
        job2_new_duration = int(request.form['duration_job2'])
        job2_delta = timedelta(minutes=job2_new_duration)
        job2_new_stoptime = (
            (datetime.combine(date(1, 1, 1), job2_new_start_time) +
             job2_delta).time())

        jobs2 = [('monday_job2', 2, 'monday'), ('tuesday_job2', 2, 'tuesday'),
                 ('wednesday_job2', 2, 'wednesday'),
                 ('thursday_job2', 2, 'thursday'), ('friday_job2', 2,
                                                    'friday'),
                 ('saturday_job2', 2, 'saturday'),
                 ('sunday_job2', 2, 'sunday')]

        #Update selected days of week based on job
        for job in jobs2:
            jobfield = job[0]
            jobnumber = job[1]
            dayofjob = job[2]
            value = bool(request.form.get(jobfield, False))
            neptune.update_day(zone, jobnumber, dayofjob, value)

        # Verify power jobs for this power outlet do not overlap each other.
        job2_time_conflict = sa_check_power_zone_times_conflict(
            zone, job2_new_start_time, job2_new_stoptime, job2_jobid)
        if job2_time_conflict:
            #zone2_with_conflict = sa_check_zone_times_jobid(job2_new_start_time, job2_new_stoptime)[0][1]
            #job2_with_conflict = sa_check_zone_times_jobid(job2_new_start_time, job2_new_stoptime)[0][2]
            flash(f'Schedule Conflict with - Job: 1', 'error')
            return render_template('powerschedule2_error.html', id=id)
        else:
            flash("Schedule Updated", "success")
            neptune.update_job_start_time(zone, '2', job2_new_start_time)
            neptune.update_job_stop_time(zone, '2', job2_new_stoptime)
            neptune.update_job_duration(zone, '2', job2_new_duration)

        return redirect(url_for('powerschedulejob2', id=id))

    else:
        print("Validation Failed")
        print(form.errors)
    return render_template('powerschedulejob2.html',
                           form=form,
                           job2_enabled=job2_enabled,
                           id=id)
Ejemplo n.º 5
0
def schedulejob1(id):
    zone1_with_conflict = ''
    job1_with_conflict = ''
    zone = f'zone{id}'
    log.debug(f'schedulejob1() called with zone: {zone}')
    form = Job1Form()
    job1_jobid = (neptune.get_schedule_by_zone_job(zone, '1')[0][0])
    job1_enabled = (neptune.get_schedule_by_zone_job(zone, '1')[0][3])
    job1_start_time = (neptune.get_schedule_by_zone_job(zone, '1')[0][4])
    job1_duration = (neptune.get_schedule_by_zone_job(zone, '1')[0][6])
    job1_monday = (neptune.get_schedule_by_zone_job(zone, '1')[0][8])
    job1_tuesday = (neptune.get_schedule_by_zone_job(zone, '1')[0][9])
    job1_wednesday = (neptune.get_schedule_by_zone_job(zone, '1')[0][10])
    job1_thursday = (neptune.get_schedule_by_zone_job(zone, '1')[0][11])
    job1_friday = (neptune.get_schedule_by_zone_job(zone, '1')[0][12])
    job1_saturday = (neptune.get_schedule_by_zone_job(zone, '1')[0][13])
    job1_sunday = (neptune.get_schedule_by_zone_job(zone, '1')[0][14])
    form.start_hour_job1.data = str(job1_start_time.hour)
    form.start_minute_job1.data = str(job1_start_time.minute)
    form.duration_job1.data = str(job1_duration)
    form.monday_job1.data = job1_monday
    form.tuesday_job1.data = job1_tuesday
    form.wednesday_job1.data = job1_wednesday
    form.thursday_job1.data = job1_thursday
    form.friday_job1.data = job1_friday
    form.saturday_job1.data = job1_saturday
    form.sunday_job1.data = job1_sunday

    if form.validate_on_submit():
        # Uodate job start/stop times and duration based on form input
        job1_new_start_hour = request.form['start_hour_job1']
        job1_new_start_minute = request.form['start_minute_job1']
        job1_new_start_time = datetime.strptime(
            job1_new_start_hour + ':' + job1_new_start_minute + ':00',
            '%H:%M:%S').time()
        job1_new_duration = int(request.form['duration_job1'])
        job1_delta = timedelta(minutes=job1_new_duration)
        job1_new_stoptime = (
            (datetime.combine(date(1, 1, 1), job1_new_start_time) +
             job1_delta).time())

        jobs1 = [('monday_job1', 1, 'monday'), ('tuesday_job1', 1, 'tuesday'),
                 ('wednesday_job1', 1, 'wednesday'),
                 ('thursday_job1', 1, 'thursday'), ('friday_job1', 1,
                                                    'friday'),
                 ('saturday_job1', 1, 'saturday'),
                 ('sunday_job1', 1, 'sunday')]

        #Update selected days of week based on job
        for job in jobs1:
            jobfield = job[0]
            jobnumber = job[1]
            dayofjob = job[2]
            value = bool(request.form.get(jobfield, False))
            neptune.update_day(zone, jobnumber, dayofjob, value)

        # Since we can only run one zone at a time, verify here that there are no conflicting jobs.
        job1_time_conflict = sa_check_zone_times_conflict(
            job1_new_start_time, job1_new_stoptime, job1_jobid)
        if job1_time_conflict:
            zone1_with_conflict = sa_check_zone_times_jobid(
                job1_new_start_time, job1_new_stoptime)[0][1]
            job1_with_conflict = sa_check_zone_times_jobid(
                job1_new_start_time, job1_new_stoptime)[0][2]
            flash(
                f'Schedule Conflict with {zone1_with_conflict} - Job: {job1_with_conflict}',
                'error')
            return render_template('schedule1_error.html', id=id)
        else:
            flash("Schedule Updated", "success")
            neptune.update_job_start_time(zone, '1', job1_new_start_time)
            neptune.update_job_stop_time(zone, '1', job1_new_stoptime)
            neptune.update_job_duration(zone, '1', job1_new_duration)
        return redirect(url_for('schedulejob1', id=id))

    else:
        print("Page Refresh")
        print(form.errors)
    return render_template('schedulejob1.html',
                           form=form,
                           job1_enabled=job1_enabled,
                           id=id)