def setAlarmState(alarmState): if alarmState not in AlarmState: logger.info("Unknown alarm state: " + alarmState) raise Exception("Unknown alarm state: " + alarmState) setDesiredAlarmState(alarmState) setDesiredAlarmStateDelay(str(datetime.datetime.now())) logger.info("Capturing state lock") with stateLock: currentAlarmState = getCurrentAlarmState() timeDelta = getLastStateChangeTimeDelta() if alarmState != currentAlarmState: logger.info("Setting Alarm state to: " + alarmState) setPreviousAlarmState(currentAlarmState) writeStringValue(alarmStateKey, alarmState) setLastStateChangeTime() setGuiUpdateTime() subject = "Alarm state is: " + alarmState + " at " + getNowStr() body = "Previous state was " + currentAlarmState + "." longbeep() sendEmail(mailto, subject, body) else: if alarmState != 'RELAXED': subject = "Alarm state is: " + alarmState body = "Alarm state has been " + alarmState + " for " + convert_timedelta_str( timeDelta) + "." sendEmail(mailto, subject, body) logger.info("We are already in state: " + alarmState + ". Nothing to do.")
def setAlarmState(alarmState): if alarmState not in AlarmState: logger.info("Unknown alarm state: " + alarmState) raise Exception("Unknown alarm state: " + alarmState) setDesiredAlarmState(alarmState) setDesiredAlarmStateDelay(str(datetime.datetime.now())) logger.info("Capturing state lock") with stateLock: currentAlarmState = getCurrentAlarmState() timeDelta = getLastStateChangeTimeDelta() if alarmState != currentAlarmState: logger.info("Setting Alarm state to: " + alarmState) setPreviousAlarmState(currentAlarmState) writeStringValue(alarmStateKey, alarmState) setLastStateChangeTime() setGuiUpdateTime() subject = "Alarm state is: " + alarmState + " at " + getNowStr() body = "Previous state was " + currentAlarmState + "." longbeep() sendEmail(mailto, subject, body) else: if alarmState != 'RELAXED': subject = "Alarm state is: " + alarmState body = "Alarm state has been " + alarmState + " for " + convert_timedelta_str(timeDelta) + "." sendEmail(mailto, subject, body) logger.info("We are already in state: " + alarmState + ". Nothing to do.")
def panic(nodeId=None, info=None, siren=True): with panicLock: logger.info("Panic called.") timeDelta = getLastPanicTimeDelta() if timeDelta.total_seconds() <= ignoreRePanicWithinSeconds: logger.info("Last panic was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.") return setLastPanicTime() setPanic(True) # for now, just send an email. subject = "Alarm! Alarm! Alarm!" body = "Siren sounded at: " + getNowStr() + ".\n" if info is not None: body += info body += "\n\n" if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" if siren is True: soundSirens() pass logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info)
def panic (nodeId = None, info = None, siren = True): with panicLock: logger.info("Panic called.") timeDelta = getLastPanicTimeDelta() if timeDelta.total_seconds() <= ignoreRePanicWithinSeconds: logger.info("Last panic was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.") return setLastPanicTime() setPanic(True) # for now, just send an email. subject = "Alarm! Alarm! Alarm!" body = "Siren sounded at: " + getNowStr() + ".\n" if info is not None: body += info body += "\n\n" if nodeId is not None: body += getNodeReport(nodeId) body += "\n\n" if siren is True: soundSirens() pass logger.info(body) sendEmail(mailto, subject, body) sendEmail(panicMailto, subject, info)