def main(): appName = "PiAlarm" alarms = Alarms() alarms_loaded_at = datetime.now() lcd = Display.Display() run_loop = True while run_loop: try: current_time = datetime.now() alarms.checkAndFire() display_time = current_time.strftime("%l:%M %p").lower() lcd.message(display_time, "Yes") except Exception, e: logging.exception("Error in main loop") print str(e) if (current_time - alarms_loaded_at).total_seconds() > (15 * 60): alarms.reload() else: time.sleep(0.3)
def checkAlarms(self): ''' runs all the alarm checkers first gets the previous and current values in a simple dictionary format to pass to the Alarms class ''' root = self.doc.getroot() xmlValsOld = None if len(root.getchildren()) > 2: xmlValsOld = root.getchildren()[-2] xmlValsNew = root.getchildren()[-1] # first element is the systemInfo node systemName = root.getchildren()[0].get("name") oldValues = self.getValuesFromXml(xmlValsOld) newValues = self.getValuesFromXml(xmlValsNew) checker = Alarms(oldValues, newValues) checker.checkForAlarms(systemName) for alarm in checker.alarms: node = etree.SubElement(xmlValsNew.alarms, alarm[0]) node._setText(alarm[1])
def getInstance(cls): if not cls.__instance: cls.__instance = Alarms() return cls.__instance