Ejemplo n.º 1
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)
Ejemplo n.º 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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
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)