def onAction(self, eventInfo):
        zone = eventInfo.getZone()

        gasSensor = zone.getDeviceByEvent(eventInfo)
        gasType = gasSensor.__class__.__name__

        if gasSensor.isTriggered():
            self.notifiedForGasType[gasType] = True
            alertMessage = 'The {} {} at {} is above normal level.'.format(
                zone.getName(), gasType, gasSensor.getValue())
            alert = Alert.createCriticalAlert(
                alertMessage, None, [], gasType,
                self.intervalBetweenAlertsInMinutes)
            AlertManager.processAlert(alert)

        else:
            if gasType in self.notifiedForGasType:
                alertMessage = 'The {} {} is back to normal.'.format(
                    zone.getName(), gasType)
                alert = Alert.createInfoAlert(alertMessage)
                AlertManager.processAlert(alert)

                del self.notifiedForGasType[gasType]

        return True
Exemple #2
0
    def onAction(self, eventInfo):
        zone = eventInfo.getZone()
        zoneManager = eventInfo.getZoneManager()

        def sendAlert():
            msg = 'The {} door has been opened for {} minutes.'.format(
                zone.getName(), self.maxElapsedTimeInSeconds / 60)

            alert = Alert.createWarningAlert(msg)
            AlertManager.processAlert(alert, zoneManager)

        for door in zone.getDevicesByType(Door):
            timer = self.timers[door] if door in self.timers else None

            if door.isOpen():
                if None != timer:
                    timer.cancel()
                    del self.timers[door]

                timer = Timer(self.maxElapsedTimeInSeconds, sendAlert)
                timer.start()
                self.timers[door] = timer
            else:
                if None != timer:
                    if timer.isAlive():
                        timer.cancel()
                    else:  # alert door now closed if a warning was previous sent
                        msg = 'The {} door is now closed.'.format(
                            zone.getName())
                        alert = Alert.createWarningAlert(msg)
                        AlertManager.processAlert(alert, zoneManager)

                    del self.timers[door]

        return True
Exemple #3
0
                def armAndSendAlert():
                    # Don't know why list comprehension version like below
                    # doesn't work, Jython just hang on this statement:
                    # if not any(z.isOccupied(elapsedTime) for z in zoneManager.getZones()):
                    # Below is a work around.
                    occupied = False
                    activeDevice = None

                    for z in zoneManager.getZones():
                        if z.isExternal():
                            continue

                        # motion sensor switches off after around 3', need to
                        # that into account.
                        motionDelayInSec = 3 * 60
                        delayTimeInSec = self.maxElapsedTimeInSeconds + motionDelayInSec

                        (occupied, activeDevice) = z.isOccupied([],
                                                                delayTimeInSec)
                        if occupied:
                            break

                    if occupied:
                        PE.logInfo(
                            'Auto-arm cancelled (activities detected @ {}).'.
                            format(activeDevice))
                    else:
                        securityPartitions[0].armAway(events)

                        msg = 'The house has been automatically armed-away (front door closed and no activity)'
                        alert = Alert.createWarningAlert(msg)
                        AlertManager.processAlert(alert, zoneManager)
Exemple #4
0
def alertIfRainInShortermForecast(event):
    forecasts = EnvCanada.retrieveHourlyForecast('Ottawa', 12)
    rainPeriods = [f for f in forecasts if \
                 'High' == f.getPrecipationProbability() or \
                 'Medium' == f.getPrecipationProbability()]
    if len(rainPeriods) > 0:
        if len(rainPeriods) == 1:
            subject = u"Possible precipation at {}".format(
                rainPeriods[0].getUserFriendlyForecastTime())
        else:
            subject = u"Possible precipation from {} to {}".format(
                rainPeriods[0].getUserFriendlyForecastTime(),
                rainPeriods[-1].getUserFriendlyForecastTime())

        body = u'Forecasts:\n'
        body += u"{:5} {:7} {:25} {:6} {:6}\n".format('Hour: ', 'Celsius',
                                                      'Condition', 'Prob.',
                                                      'Wind')
        for f in forecasts:
            body += unicode(f) + '\n'

        alert = Alert.createInfoAlert(subject, body)
        result = AlertManager.processAlert(alert, zm)
        if not result:
            PE.logInfo('Failed to send rain alert')
    def updateState(self, value, zone, zoneManager):
        '''
        Update this object with the latest value.
        If the value is outside the range, an warning alert will be sent.
        If the value is back to the normal range, an info alert will be sent.
        '''
        if value >= self.minValue and value <= self.maxValue:
            if self.sentAlert: # send an info alert that the value is back to normal
                self.resetStates()

                msg = 'The {} {} at {}{} is back to the normal range ({}% - {}%).'.format(
                        zone.getName(), self.label, value, self.unit,
                        self.minValue, self.maxValue)
                alert = Alert.createInfoAlert(msg)

                if self.adminAlert:
                    AlertManager.processAdminAlert(alert)
                else:
                    AlertManager.processAlert(alert)

        else:
            alertMessage = ''
            if value <= self.nextMinNotificationThreshold:
                alertMessage = 'The {} {} at {}{} is below the threshold of {}%.'.format(
                        zone.getName(), self.label, value, self.unit, self.minValue)
                self.nextMinNotificationThreshold -= self.notificationStepValue
            elif value >= self.nextMaxNotificationThreshold:
                alertMessage = 'The {} {} at {}{} is above the threshold of {}%.'.format(
                        zone.getName(), self.label, value, self.unit, self.maxValue)
                self.nextMaxNotificationThreshold += self.notificationStepValue

            if alertMessage != '':
                alert = Alert.createWarningAlert(alertMessage, None, [], 
                        self.module, self.intervalBetweenAlertsInMinutes)
                if self.adminAlert:
                    AlertManager.processAdminAlert(alert)
                else:
                    AlertManager.processAlert(alert)

                self.sentAlert = True
Exemple #6
0
def _checkAndSendAlert(zoneManager, checkFunction, deviceTypeString, thresholdInSeconds):
    inactiveDevices = checkFunction(zm, thresholdInSeconds)

    if len(inactiveDevices) > 0:
        subject = "{} inactive {} devices".format(
                len(inactiveDevices), deviceTypeString)
        body = "The following devices haven't triggered "\
               "in the last {} hours\r\n  - ".format(
                       thresholdInSeconds / 3600)
        body += "\r\n  - ".join(inactiveDevices)

        alert = Alert.createInfoAlert(subject, body)
        if not AlertManager.processAdminAlert(alert):
            PE.logInfo('Failed to send inactive {} device alert'.format(deviceTypeString))
    else:
        PE.logInfo("No inactive {} devices detected.".format(deviceTypeString))
Exemple #7
0
        def sendAlert():
            msg = 'The {} door has been opened for {} minutes.'.format(
                zone.getName(), self.maxElapsedTimeInSeconds / 60)

            alert = Alert.createWarningAlert(msg)
            AlertManager.processAlert(alert, zoneManager)