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 setLocalIp (): # This is a relatively expensive call. # http://stackoverflow.com/a/1267524/215120 try: ip = [(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1] except: ip = "127.0.0.1" logger.info("Setting Local IP to: " + ip) writeStringValue(localIpKey, ip)
def setLocalIp(): # This is a relatively expensive call. # http://stackoverflow.com/a/1267524/215120 try: ip = [(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)] ][0][1] except: ip = "127.0.0.1" logger.info("Setting Local IP to: " + ip) writeStringValue(localIpKey, ip)
def setDesiredAlarmStateDelay(date): writeStringValue(alarmDesiredStateDelay, date) setGuiUpdateTime()
def setPanic (panic): if panic: writeStringValue(alarmPanicKey, "TRUE") else: writeStringValue(alarmPanicKey, "FALSE") setGuiUpdateTime()
def setPreviousAlarmState(state): writeStringValue(alarmPreviousStateKey, state)
def setDesiredAlarmState(state): writeStringValue(alarmDesiredStateKey, state) setGuiUpdateTime()
def setDesiredAlarmState (state): writeStringValue(alarmDesiredStateKey, state) setGuiUpdateTime()
def setPersistent(persistent): if persistent: writeStringValue(statePersistentKey, "TRUE") else: writeStringValue(statePersistentKey, "FALSE") setGuiUpdateTime()
def setLastTime(key): now = str(datetime.datetime.now()) logger.info("Setting key: " + key + ", to " + now) writeStringValue(key,now)
def resetAlertPanicTime(): writeStringValue(alertPanicTimeKey, str(datetime.datetime(1970, 1, 1))) setGuiUpdateTime( ) # GUI needs to be updated to reflect that alarm will fire.
def setAlertPanicTime(alertPanicTime): writeStringValue(alertPanicTimeKey,alertPanicTime) setGuiUpdateTime() # GUI needs to be updated to reflect that alarm will fire.
def resetAlertPanicTime(): writeStringValue(alertPanicTimeKey,str(datetime.datetime(1970,1,1))) setGuiUpdateTime() # GUI needs to be updated to reflect that alarm will fire.
def setAlarmCode(alarmCode): logger.info("Setting Alarm code...") sendEmail(mailto, "Setting Alarm code") md5Alarmcode = hashlib.md5(alarmCode).hexdigest() writeStringValue(alarmCodeKey, md5Alarmcode)
def setPersistent (persistent): if persistent: writeStringValue(statePersistentKey, "TRUE") else: writeStringValue(statePersistentKey, "FALSE") setGuiUpdateTime()
def setDesiredAlarmStateDelay (date): writeStringValue(alarmDesiredStateDelay, date) setGuiUpdateTime()
def setLastTime(key): now = str(datetime.datetime.now()) logger.info("Setting key: " + key + ", to " + now) writeStringValue(key, now)
def setAlertPanicTime(alertPanicTime): writeStringValue(alertPanicTimeKey, alertPanicTime) setGuiUpdateTime( ) # GUI needs to be updated to reflect that alarm will fire.
def setPanic(panic): if panic: writeStringValue(alarmPanicKey, "TRUE") else: writeStringValue(alarmPanicKey, "FALSE") setGuiUpdateTime()
#!/usr/bin/env python # @author rouble matta import sys from CacheUtils import writeStringValue print writeStringValue(sys.argv[1], sys.argv[2])
def setPreviousAlarmState (state): writeStringValue(alarmPreviousStateKey, state)