Changeset - 18ae0de640b9
[Not reviewed]
default
0 1 0
matthewreed - 9 years ago 2016-08-08 20:01:11

Added timezone compensation for EST timezone
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
hydrobot.py
Show inline comments
 
@@ -9,12 +9,13 @@ from canard.hw import socketcan
 
from canard.hw import cantact
 
from canard.file import jsondb
 
from influxdb import InfluxDBClient
 
from influxdb import SeriesHelper
 
from apscheduler.schedulers.background import BackgroundScheduler
 
import PID
 
from pytz import timezone
 

	
 
#TODO
 
#fix temperature offsets
 
#database time interval logging
 
#set initial state for cron timers
 

	
 
@@ -144,12 +145,13 @@ class CanBus:
 
        
 
class Scheduler:
 
    
 
    def __init__(self, canbus):
 
        self.canbus = canbus
 
        self.apscheduler = BackgroundScheduler()
 
        self.apscheduler.configure(timezone=timezone('US/Eastern'))
 
        
 
    def start(self):
 
        self.apscheduler.start()
 
        
 
        for section in config.sections():
 
            if "timer" in section:
 
@@ -169,13 +171,13 @@ class Scheduler:
 
                        on_duration = ast.literal_eval(item[1])
 
                    if item[0] == 'off_duration':
 
                        off_duration = ast.literal_eval(item[1])
 
                if trigger == 'cron':
 
                    on_job = self.apscheduler.add_job(self.canbus.set_output, trigger, [module, output, 1], day = on_time[0], day_of_week = on_time[1], hour = on_time[2], minute = on_time[3], second = on_time[4])
 
                    off_job = self.apscheduler.add_job(self.canbus.set_output, trigger, [module, output, 0], day = off_time[0], day_of_week = off_time[1], hour = off_time[2], minute = off_time[3], second = off_time[4])
 
                                        
 
                    
 
                    #evalute the current state of the cron trigger and set output on if needed
 
                    if on_job.next_run_time > off_job.next_run_time:
 
                        self.canbus.set_output(module, output, 1)
 
                    else:
 
                        self.canbus.set_output(module, output, 0)
 
                    
0 comments (0 inline, 0 general)