Exemplo n.º 1
0
    def setprogram(self, program, message = ""):
        sql = """SELECT program_id, code, name, relative_times, repeat_program, default_program, selected
                         FROM programs
                         WHERE module = {0}
                         AND code = {1}""".format(db.dbstr(self.name()), db.dbstr(program))

        programs = db.read(sql, 0, 1)

        self.program = {
            ProgramCodes.PROGRAM_ID:programs[0]['program_id'],
            ProgramCodes.CODE:programs[0]['code'],
            ProgramCodes.NAME:programs[0]['name'],
            ProgramCodes.RELATIVE_TIMES:programs[0]['relative_times'],
            ProgramCodes.REPEAT_PROGRAM:programs[0]['repeat_program'],
            ProgramCodes.DEFAULT_PROGRAM:programs[0]['default_program'],
            ProgramCodes.SELECTED:programs[0]['selected'],
            ProgramCodes.START_TIME:datetime.datetime.now(),
            ProgramCodes.MESSAGE:message
            }
    
        if self.program[ProgramCodes.REPEAT_PROGRAM]:
            self.debug("Setting program {0} as selected program".format(self.program[ProgramCodes.CODE]))
            db.write("UPDATE programs SET selected = 0 WHERE module = {0} AND selected = 1".format(db.dbstr(self.name())))
            db.write("UPDATE programs SET selected = 1 WHERE program_id = {0}".format(self.program[ProgramCodes.PROGRAM_ID]))
        
        self.onprogramchanged()

        return True
Exemplo n.º 2
0
    def processbroadcastrequest(self, request):
        sql = """SELECT program_id
                         FROM programs
                         WHERE module = {0}
                         AND code = {1}""".format(db.dbstr(self.name()), db.dbstr(request[MessageCodes.VALUE]))
        if db.read(sql, 0, 1):
            if self.program[ProgramCodes.REPEAT_PROGRAM] == 0:
                self.programStack.append(self.program)
                
            self.setprogram(request[MessageCodes.VALUE], request[MessageCodes.MESSAGE])
            self.loginformation("Program request", "Program {0} requested by {1}.".format(request[MessageCodes.VALUE], request[MessageCodes.WORKER]))

        return True;
Exemplo n.º 3
0
    def setup(self):
        self.cleanup("Initialising devices")
        
        sql = """
SELECT sensor, value, date
FROM sensor_log
WHERE module = """ + db.dbstr(self.name()) + """ 
AND sensor = """ + db.dbstr(Sensors.DISPLAY_TEMP) + """ 
AND date > NOW() - INTERVAL 1 DAY
ORDER BY date
"""
        temps = db.read(sql, 0, 1000)
        for temp_reading in temps:
            self.temp_history.append(temp_reading)

        self.debug("{0} items added to list".format(len(self.temp_history)))
Exemplo n.º 4
0
    def setdefaultprogram(self):
        sql = """SELECT program_id, code, name, relative_times, repeat_program, default_program, selected
                 FROM programs
                 WHERE module = {0}
                 AND (default_program = 1 OR selected = 1)
                 ORDER BY selected DESC, default_program DESC""".format(db.dbstr(self.name()))
        programs = db.read(sql, 0, 1)

        if not programs:
            self.program = {}
        else:
            self.program = {
                ProgramCodes.PROGRAM_ID:programs[0]['program_id'],
                ProgramCodes.CODE:programs[0]['code'],
                ProgramCodes.NAME:programs[0]['name'],
                ProgramCodes.RELATIVE_TIMES:programs[0]['relative_times'],
                ProgramCodes.REPEAT_PROGRAM:programs[0]['repeat_program'],
                ProgramCodes.DEFAULT_PROGRAM:programs[0]['default_program'],
                ProgramCodes.SELECTED:programs[0]['selected'],
                ProgramCodes.START_TIME:datetime.datetime.now(),
                ProgramCodes.MESSAGE:""
                }

        self.onprogramchanged()

        return True
Exemplo n.º 5
0
    def getprograms(self):
        programID = self.program[ProgramCodes.PROGRAM_ID] if self.program else 0
        
        sql = """SELECT program_id, code, name, 0 AS running
                FROM programs
                WHERE module = {0}
                AND (show_in_list = 1 OR program_id = {1})
                ORDER BY default_program DESC, name""".format(db.dbstr(self.name()), db.dbstr(programID))
                
        programs = db.read(sql)

        for program in programs:
            if program['program_id'] == programID:
                program['running'] = 1
        
        return programs
Exemplo n.º 6
0
    def getprograms(self):
        sql = """SELECT program_id, code, name, 0 AS running
                FROM programs
                WHERE module = {0}
                ORDER BY default_program DESC, name""".format(db.dbstr(self.name()))
                
        programs = db.read(sql)

        for program in programs:
            if program['program_id'] == self.program['program_id']:
                program['running'] = 1
        
        return programs
Exemplo n.º 7
0
 def setdefaultprogram(self):
     sql = """SELECT program_id, code, relative_times, repeat_program
              FROM programs
              WHERE module = {0}
              AND (default_program = 1 OR selected = 1)
              ORDER BY selected DESC, default_program DESC""".format(db.dbstr(self.name()))
     programs = db.read(sql, 0, 1)
     self.program = {
         'program_id':programs[0]['program_id'],
         'code':programs[0]['code'],
         'relative_times':programs[0]['relative_times'],
         'repeat_program':programs[0]['repeat_program']
         }
Exemplo n.º 8
0
    def setprogram(self, program):
        sql = """SELECT program_id, code, relative_times, repeat_program
                         FROM programs
                         WHERE module = {0}
                         AND code = {1}""".format(db.dbstr(self.name()), db.dbstr(program))

        programs = db.read(sql, 0, 1)
        self.program = {
            'program_id':programs[0]['program_id'],
            'code':programs[0]['code'],
            'relative_times':programs[0]['relative_times'],
            'repeat_program':programs[0]['repeat_program']
            }
        
        if self.program['repeat_program']:
            self.debug("Setting program {0} as selected program".format(self.program['code']))
            db.write("UPDATE programs SET selected = 0 WHERE module = {0} AND selected = 1".format(db.dbstr(self.name())))
            db.write("UPDATE programs SET selected = 1 WHERE program_id = {0}".format(self.program['program_id']))
        
        self.looprequest = True
        
        # TODO: Raise exception? Or return False for invalid program?
        return True