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
 
@@ -3,24 +3,25 @@ import time
 
import _thread
 
import ast
 
import configparser
 
import datetime
 
from canard import can, messaging
 
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
 

	
 
config = configparser.ConfigParser(allow_no_value = True)
 
config.read("hydrobot.conf")
 
DEBUG_CAN = config.getboolean("debug", "can")
 
DEBUG_CAN_DETAIL = config.getboolean("debug", "can_detail")
 
DEBUG_TIMER = config.getboolean("debug", "timer")
 

	
 
@@ -138,24 +139,25 @@ class CanBus:
 
            MySeriesHelper(measurement='output_2', value=state)
 
        if msg.lookup_signal(output) == msg.Output3:
 
            MySeriesHelper(measurement='output_3', value=state)
 
        if msg.lookup_signal(output) == msg.Output4:
 
            MySeriesHelper(measurement='output_4', value=state)
 
        
 
        
 
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:
 
                items = config.items(section)
 
                for item in items:
 
                    if item[0] == 'trigger':
 
                        trigger = item[1]
 
                    if item[0] == 'module':
 
                        module = item[1]
 
@@ -163,25 +165,25 @@ class Scheduler:
 
                        output = item[1]
 
                    if item[0] == 'on_time':
 
                        on_time = ast.literal_eval(item[1])
 
                    if item[0] == 'off_time':
 
                        off_time = ast.literal_eval(item[1])
 
                    if item[0] == 'on_duration':
 
                        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)
 
                    
 
                if trigger == 'interval':
 
                    self.apscheduler.add_job(self.interval_off, trigger, [module, output, section + "_off", section + "_on", on_duration], id = section + "_off", weeks = off_duration[0], days = off_duration[1], hours = off_duration[2], minutes = off_duration[3], seconds = off_duration[4])
 
                    timer = self.apscheduler.add_job(self.interval_on, trigger, [module, output, section + "_off", section + "_on", off_duration], id = section + "_on", weeks = on_duration[0], days = on_duration[1], hours = on_duration[2], minutes = on_duration[3], seconds = on_duration[4])
 
                    timer.pause()
 
                    self.interval_off(module, output, section + "_off", section + "_on", on_duration)
 
                    
0 comments (0 inline, 0 general)