Example #1
0
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.")
Example #2
0
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.")
Example #3
0
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)
Example #4
0
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)
Example #5
0
def setDesiredAlarmStateDelay(date):
    writeStringValue(alarmDesiredStateDelay, date)
    setGuiUpdateTime()
Example #6
0
def setPanic (panic):
    if panic:
        writeStringValue(alarmPanicKey, "TRUE")
    else:
        writeStringValue(alarmPanicKey, "FALSE")
    setGuiUpdateTime()
Example #7
0
def setPreviousAlarmState(state):
    writeStringValue(alarmPreviousStateKey, state)
Example #8
0
def setDesiredAlarmState(state):
    writeStringValue(alarmDesiredStateKey, state)
    setGuiUpdateTime()
Example #9
0
def setDesiredAlarmState (state):
    writeStringValue(alarmDesiredStateKey, state)
    setGuiUpdateTime()
Example #10
0
def setPersistent(persistent):
    if persistent:
        writeStringValue(statePersistentKey, "TRUE")
    else:
        writeStringValue(statePersistentKey, "FALSE")
    setGuiUpdateTime()
Example #11
0
def setLastTime(key):
    now = str(datetime.datetime.now())
    logger.info("Setting key: " + key + ", to " + now)
    writeStringValue(key,now)
Example #12
0
def resetAlertPanicTime():
    writeStringValue(alertPanicTimeKey, str(datetime.datetime(1970, 1, 1)))
    setGuiUpdateTime(
    )  # GUI needs to be updated to reflect that alarm will fire.
Example #13
0
def setAlertPanicTime(alertPanicTime):
    writeStringValue(alertPanicTimeKey,alertPanicTime)
    setGuiUpdateTime() # GUI needs to be updated to reflect that alarm will fire.
Example #14
0
def resetAlertPanicTime():
    writeStringValue(alertPanicTimeKey,str(datetime.datetime(1970,1,1)))
    setGuiUpdateTime() # GUI needs to be updated to reflect that alarm will fire.
Example #15
0
def setAlarmCode(alarmCode):
    logger.info("Setting Alarm code...")
    sendEmail(mailto, "Setting Alarm code")
    md5Alarmcode = hashlib.md5(alarmCode).hexdigest()
    writeStringValue(alarmCodeKey, md5Alarmcode)
Example #16
0
def setPersistent (persistent):
    if persistent:
        writeStringValue(statePersistentKey, "TRUE")
    else:
        writeStringValue(statePersistentKey, "FALSE")
    setGuiUpdateTime()
Example #17
0
def setDesiredAlarmStateDelay (date):
    writeStringValue(alarmDesiredStateDelay, date)
    setGuiUpdateTime()
Example #18
0
def setAlarmCode(alarmCode):
    logger.info("Setting Alarm code...")
    sendEmail(mailto, "Setting Alarm code")
    md5Alarmcode = hashlib.md5(alarmCode).hexdigest()
    writeStringValue(alarmCodeKey, md5Alarmcode)
Example #19
0
def setLastTime(key):
    now = str(datetime.datetime.now())
    logger.info("Setting key: " + key + ", to " + now)
    writeStringValue(key, now)
Example #20
0
def setAlertPanicTime(alertPanicTime):
    writeStringValue(alertPanicTimeKey, alertPanicTime)
    setGuiUpdateTime(
    )  # GUI needs to be updated to reflect that alarm will fire.
Example #21
0
def setPanic(panic):
    if panic:
        writeStringValue(alarmPanicKey, "TRUE")
    else:
        writeStringValue(alarmPanicKey, "FALSE")
    setGuiUpdateTime()
Example #22
0
#!/usr/bin/env python
# @author rouble matta

import sys
from CacheUtils import writeStringValue

print writeStringValue(sys.argv[1], sys.argv[2])
Example #23
0
def setPreviousAlarmState (state):
    writeStringValue(alarmPreviousStateKey, state)