Пример #1
0
    def __init__(self):
        # Configure database
        sqlite3.register_adapter(bool, str)
        sqlite3.register_converter("BOOLEAN", lambda v: 'T' in v)

        # THERMOSTAT.DB
        # TABLES: status, schedule, settings
        self.thermConn = sqlite3.connect(
            "logs/thermostat.db",
            detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES,
            check_same_thread=False)  #use this to save datetime
        self.thermConn.row_factory = sqlite3.Row  # returned rows can be called with case-insensitive column names
        self.thermCursor = self.thermConn.cursor()

        # LOGS.DB
        # TABLES: logging, hourlyWeather, dailyWeather
        self.logsConn = sqlite3.connect(
            "logs/logs.db",
            detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES,
            check_same_thread=False)  #use this to save datetime
        self.logsConn.row_factory = sqlite3.Row  # returned rows can be called with case-insensitive column names
        self.logsCursor = self.logsConn.cursor()

        self.config = self.thermCursor.execute(
            'SELECT * FROM settings').fetchone()

        #set signal handlers
        for sig in [signal.SIGTERM, signal.SIGQUIT, signal.SIGINT]:
            signal.signal(sig, self.signal_handler)
        signal.signal(signal.SIGHUP, self.reload)

        # used for scheduling on/off times
        self.calendar = scheduler.Calendar()

        self.configureGPIO()
        self.lastLog = datetime.now()
        self.mailLog = {}
        self.lastWeatherUpdate = datetime.now() + timedelta(hours=-2)

        # if database is corrupt, let the user know
        if self.thermCursor.execute(
                'PRAGMA quick_check').fetchone()[0] != 'ok':
            self.sendErrorMail("The thermostat database is corrupt!")
        if self.logsCursor.execute('PRAGMA quick_check').fetchone()[0] != 'ok':
            self.sendErrorMail("The logs database is corrupt!")

        self.getStatus()

        self.sendErrorMail("Thermostat is starting")
Пример #2
0
# get CONFIG settings
CONFIG = thermCursor.execute('SELECT * FROM settings').fetchone()

# TABLES: logging, hourlyWeather, dailyWeather
logsConn = sqlite3.connect(
    "logs/logs.db",
    detect_types=sqlite3.PARSE_DECLTYPES
    | sqlite3.PARSE_COLNAMES,  #use this to save datetime
    check_same_thread=False)
# returned rows can be called with case-insensitive column names
logsConn.row_factory = sqlite3.Row
logsCursor = logsConn.cursor()

#load any scheduled items
calendar = scheduler.Calendar()

try:
    GPIO.setwarnings(False)
    if 'BCM' in CONFIG['numbering_scheme']:
        GPIO.setmode(GPIO.BCM)
    else:
        GPIO.setmode(GPIO.BOARD)
    GPIO.setup([CONFIG['heater_pin'], CONFIG['ac_pin'], CONFIG['fan_pin']],
               GPIO.OUT)
    settingsRedirect = False
except (ValueError, TypeError):
    settingsRedirect = True
''' WORKER FUNCTIONS '''
'''''' '''''' '''''' ''''''