Exemple #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.")
Exemple #2
0
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)
Exemple #3
0
def setDelayedAlarmState (alarmState, delay, desiredStateAlreadySet = False):
    if alarmState not in AlarmState:
        logger.info("Unknown alarm state: " + alarmState)
        raise Exception("Unknown alarm state: " + alarmState)

    if desiredStateAlreadySet == False:
        setDesiredAlarmState(alarmState)
        setDesiredAlarmStateDelay(str(datetime.datetime.now() + datetime.timedelta(seconds=delay)))
    else:
        logger.info("Desired state has already been set.")
    currentAlarmState = getCurrentAlarmState()
    timeDelta = getLastStateChangeTimeDelta()
    if alarmState != currentAlarmState:
        desiredAlarmStateDelay = getDesiredAlarmStateDelay() 
        while True: 
            secondsLeft = secondsLeftFromString(desiredAlarmStateDelay)
            if secondsLeft < 0:
                break
            logger.info("Setting state: " + alarmState + " after " + str(secondsLeft) + " seconds.")
            sleep(1)
        currentDesiredAlarmState = getDesiredAlarmState()
        if (currentDesiredAlarmState != alarmState):
            logger.info("Not setting State!!. The current desired state is: " + currentDesiredAlarmState + " and we were waiting to set it to " + alarmState)
            return
        setAlarmState(alarmState)
        alarmState = getCurrentAlarmState()
        logger.info("Alarm state has been updated to: " + alarmState)
    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.")
Exemple #4
0
def AlertIfArmed(nodeId, current, previous):
    with alertLock:
        name = getNodeName(nodeId)
        alarmState = getCurrentAlarmState()
        if (alarmState != "DISARMED"):
            logger.info("Sensor tripped on node " + name + " in alarm state: " + alarmState + " on " + str(current.time))
            timeDelta = getLastAlertTimeDelta()
            if timeDelta.total_seconds() <= ignoreReAlertWithinSeconds:
                logger.info("Last alert was " + convert_timedelta_str(timeDelta) + " ago. Ignoring.")
                return
            setLastAlertTime()
            alarmStateDelay = getAlarmStateDelayForNode(nodeId, alarmState)
            if alarmStateDelay is None:
                logger.info("No delay defined for alarm state: [" + alarmState + "]. Defaulting to 10 seconds.")
                alarmStateDelay = 10
            then = datetime.datetime.now() + datetime.timedelta(seconds=alarmStateDelay)
            setAlertPanicTime(str(then))
            logger.info("We are in the following armed state: [" + alarmState + "]. Siren will be enabled in " + str(alarmStateDelay) + " seconds")
            subject = "[" + alarmState + "] Sensor tripped on node " + name + " on " + str(current.time)
            body = "Siren will fire in " + str(alarmStateDelay) + " seconds at " + str(then)
            sendEmail(mailto, subject, body)
            sleepWithBeep(then)
            # Now check is enduser has been able to disarm the alarm
            if (getCurrentAlarmState() != "DISARMED"):
                notification = getLatestNotification(nodeId)
                panic(nodeId = nodeId, info = "Triggered by " + name + ". " + name + " is currently " + getSensorState(notification.value) + ".")
            else:
                sendEmail(mailto, "Alarm disarmed in time!", "")
                logger.info("Alarm disarmed in time!")
            resetAlertPanicTime()
Exemple #5
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.")
Exemple #6
0
def EmailAlertAlways(nodeId, current, previous):
    name = getNodeName(nodeId)
    alarmState = getCurrentAlarmState()
    subject = "[" + str(alarmState) + "] " + str(name) + " is " + getSensorState(current.value) + " at " + str(current.time)
    body = name + " had been " + getSensorState(previous.value) + " for " + getTimeElapsed_HHMMSS(previous.time) + ".\n\n"
    body += "Current: " + str(current) + "\n"
    body += "Previous: " + str(previous) + "\n"
    body += getNodeReport(nodeId)
    sendEmail(mailto, subject, body);
def ReportLowBatteryStatus(nodeId, current):
    try:
        batteryValue = int(current.value)
    except:
        batteryValue = 0

    if (batteryValue < 30) or (batteryValue == 255) : 
        name = getNodeName(nodeId)
        subject = "Low Battery! " + str(name) + "'s battery level is at " + str(current.value) + "% at " + str(current.time)
        body = "Current: " + str(current) + "\n\n"
        body += getNodeReport(nodeId)
        sendEmail(mailto, subject, body);
Exemple #8
0
def ReportLowBatteryStatus(nodeId, current):
    try:
        batteryValue = int(current.value)
    except:
        batteryValue = 0

    if (batteryValue < 30) or (batteryValue == 255):
        name = getNodeName(nodeId)
        subject = "Low Battery! " + str(
            name) + "'s battery level is at " + str(
                current.value) + "% at " + str(current.time)
        body = "Current: " + str(current) + "\n\n"
        body += getNodeReport(nodeId)
        sendEmail(mailto, subject, body)
Exemple #9
0
def unpanic(nodeId=None, info=None):
    with panicLock:
        logger.info("unPanic called.")
        if isPanic():
            setPanic(False)
            subject = "Unpanic! Alarm silenced!"
            body = "Alarm silenced at: " + str(datetime.datetime.now()) + ".\n"
            if info is not None:
                body += info
            if nodeId is not None:
                body += getNodeReport(nodeId)
                body += "\n\n"
            silenceSirens()
            logger.info(body)
            sendEmail(mailto, subject, body)
            sendEmail(panicMailto, subject, info)
        else:
            logger.info("Not panicing. Nothing to do.")
Exemple #10
0
def unpanic (nodeId = None, info = None):
    with panicLock:
        logger.info("unPanic called.")
        if isPanic():
            setPanic(False)
            subject = "Unpanic! Alarm silenced!"
            body = "Alarm silenced at: " + str(datetime.datetime.now()) + ".\n"
            if info is not None:
                body += info
            if nodeId is not None:
                body += getNodeReport(nodeId)  
                body += "\n\n"
            silenceSirens()
            logger.info(body)
            sendEmail(mailto, subject, body)
            sendEmail(panicMailto, subject, info)
        else:
            logger.info("Not panicing. Nothing to do.")
Exemple #11
0
def setDelayedAlarmState(alarmState, delay, desiredStateAlreadySet=False):
    if alarmState not in AlarmState:
        logger.info("Unknown alarm state: " + alarmState)
        raise Exception("Unknown alarm state: " + alarmState)

    if desiredStateAlreadySet == False:
        setDesiredAlarmState(alarmState)
        setDesiredAlarmStateDelay(
            str(datetime.datetime.now() + datetime.timedelta(seconds=delay)))
    else:
        logger.info("Desired state has already been set.")
    currentAlarmState = getCurrentAlarmState()
    timeDelta = getLastStateChangeTimeDelta()
    if alarmState != currentAlarmState:
        desiredAlarmStateDelay = getDesiredAlarmStateDelay()
        while True:
            secondsLeft = secondsLeftFromString(desiredAlarmStateDelay)
            if secondsLeft < 0:
                break
            logger.info("Setting state: " + alarmState + " after " +
                        str(secondsLeft) + " seconds.")
            sleep(1)
        currentDesiredAlarmState = getDesiredAlarmState()
        if (currentDesiredAlarmState != alarmState):
            logger.info("Not setting State!!. The current desired state is: " +
                        currentDesiredAlarmState +
                        " and we were waiting to set it to " + alarmState)
            return
        setAlarmState(alarmState)
        alarmState = getCurrentAlarmState()
        logger.info("Alarm state has been updated to: " + alarmState)
    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.")
Exemple #12
0
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)
from Utils import convert_timedelta_str
from RobotUtils import sendEmail
from LoggerUtils import setupCronbotLogger

logger = setupCronbotLogger()

mailto = getMailto()
maxOpenTimeInSeconds = 240
now = datetime.datetime.now()

for node in getNodes():
    if not isDoorWindowOrMotion(node):
        continue
    name = getNodeName(node)
    logger.info("Testing node: " + node + ":" + name)

    notification = getEarliestNotificationOfCurrentState(node, logger=logger)
    if not notification:
        logger.info("No notifications for node: " + name)
    elif notification.value == "False":
        delta = now - notification.time
        logger.info(name + " has been closed for " + convert_timedelta_str(delta))
    elif notification.value == "True":
        delta = now - notification.time
        logger.info(name + " has been open for " + convert_timedelta_str(delta))
        if delta.total_seconds() > maxOpenTimeInSeconds:
            subject = name + " has been open for " + convert_timedelta_str(delta)
            sendEmail(mailto, subject, getNodeReport(node))
    else:
        logger.info("Can not determine state of: " + getNodeName(node) + " since it is [" + notification.value + "]")
Exemple #14
0
def setAlarmCode(alarmCode):
    logger.info("Setting Alarm code...")
    sendEmail(mailto, "Setting Alarm code")
    md5Alarmcode = hashlib.md5(alarmCode).hexdigest()
    writeStringValue(alarmCodeKey, md5Alarmcode)
Exemple #15
0
def setAlarmCode(alarmCode):
    logger.info("Setting Alarm code...")
    sendEmail(mailto, "Setting Alarm code")
    md5Alarmcode = hashlib.md5(alarmCode).hexdigest()
    writeStringValue(alarmCodeKey, md5Alarmcode)
Exemple #16
0
logger = setupCronbotLogger()

mailto = getMailto()
maxCloseTimeInSeconds = 28440
now = datetime.datetime.now()

for node in getNodes():
    if not isDoorWindowOrMotion(node):
        continue
    name = getNodeName(node)
    logger.info("Testing node: " + node + ":" + name)

    notification = getEarliestNotificationOfCurrentState(node, logger=logger)
    if not notification:
        logger.info("No notifications for node: " + name)
    elif (notification.value == 'False'):
        delta = now - notification.time
        logger.info(name + " has been closed for " +
                    convert_timedelta_str(delta))
        if delta.total_seconds() > maxCloseTimeInSeconds:
            subject = name + " has been closed for " + convert_timedelta_str(
                delta)
            sendEmail(mailto, subject, getNodeReport(node))
    elif (notification.value == 'True'):
        delta = now - notification.time
        logger.info(name + " has been open for " +
                    convert_timedelta_str(delta))
    else:
        logger.info("Can not determine state of: " + getNodeName(node) +
                    " since it is [" + notification.value + "]")
def ReportBatteryStatus(nodeId, current):
    name = getNodeName(nodeId)
    subject = str(name) + "'s battery level is at " + str(current.value) + "% at " + str(current.time)
    body = "Current: " + str(current) + "\n\n"
    body += getNodeReport(nodeId)
    sendEmail(mailto, subject, body);