Example #1
0
    def setArmingMode(self, newArmingMode, sendCommand=False):
        '''
        Sets the zones current arming mode
        '''
        oldArmingMode = self._armingMode

        if newArmingMode not in [
                ARMINGMODE['DISARMED'], ARMINGMODE['ARMED_HOME'],
                ARMINGMODE['ARMED_AWAY']
        ]:
            raise IdeAlarmError('Trying to set an invalid arming mode: ' +
                                str(newArmingMode))

        # There might be open sensors when trying to arm. If so, the custom function onArmingWithOpenSensors
        # gets called. (That doesn't necessarily need to be an error condition).
        #  However if the zone has been configured not to allow opened sensors during arming,
        # the zone status will be set to ERROR and onZoneStatusChange will be able to trap track it down.
        if newArmingMode in [ARMINGMODE['ARMED_AWAY'], ARMINGMODE['ARMED_HOME']] \
        and self.getZoneStatus() != ZONESTATUS['ARMING'] and self.getZoneStatus() is not None \
        and self.openSections > 0:
            if 'onArmingWithOpenSensors' in dir(custom):
                custom.onArmingWithOpenSensors(self, newArmingMode)
            if not self.canArmWithTrippedSensors:
                self.setZoneStatus(
                    ZONESTATUS['ERROR'],
                    errorMessage='Arming is not allowed with open sensors')
                self.log.error('Zone \'' + self.name.decode('utf-8') +
                               '\' can not be set to new arming mode: ' +
                               kw(ARMINGMODE, newArmingMode) +
                               ' due to that there are open sensors!')
                import time
                time.sleep(1)
                self.setZoneStatus(ZONESTATUS['NORMAL'])
                return

        # Don't set arming mode to 'ARMED_AWAY' immediately, we need to wait for the exit timer
        # self.getZoneStatus() returns None when initializing
        if newArmingMode == ARMINGMODE['ARMED_AWAY'] \
        and self.getZoneStatus() is not None and self.getZoneStatus() != ZONESTATUS['ARMING']:
            self.setZoneStatus(ZONESTATUS['ARMING'])
            postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Exit_Timer',
                                 'ON')
            return
        self._armingMode = newArmingMode

        # Sync the Item
        postUpdateCheckFirst(self.armingModeItem, newArmingMode, sendCommand)

        # Call custom function if available
        if 'onArmingModeChange' in dir(custom):
            custom.onArmingModeChange(self, newArmingMode, oldArmingMode)

        # Whenever the arming mode is set, reset the zones status to NORMAL
        self.setZoneStatus(ZONESTATUS['NORMAL'])
Example #2
0
    def onSensorChange(self, sensor):
        '''
        Called whenever an enabled sensor has tripped ON or OPEN
        '''
        if self.getArmingMode() not in [ARMINGMODE['ARMED_HOME'], ARMINGMODE['ARMED_AWAY']] \
        or self.getZoneStatus() not in [ZONESTATUS['NORMAL']] \
        or (self.getArmingMode() == ARMINGMODE['ARMED_HOME'] and sensor.sensorClass == 'B') \
        or getItemValue('Z'+str(self.zoneNumber)+'_Exit_Timer', 'OFF') == 'ON':
            self.log.info(
                sensor.name.decode('utf-8') +
                ' was tripped, but we are ignoring it')
            return

        self.setZoneStatus(ZONESTATUS['TRIPPED'])
        self.log.info(
            sensor.name.decode('utf-8') + ' was tripped, starting entry timer')
        postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Entry_Timer', 'ON')
Example #3
0
    def onEntryTimer(self):
        '''
        Called whenever the entry timer times out.
        '''
        # Double check that the zone status is tripped, we can probably remove this check later
        if self.getZoneStatus() not in [ZONESTATUS['TRIPPED']]:
            raise IdeAlarmError(
                'Entry Timer timed out but zone status is not tripped')
        self.setZoneStatus(ZONESTATUS['ALERT'])

        # We need to make some noise here!
        if not self.alarmTestMode:
            for alertDevice in self.alertDevices:
                sendCommandCheckFirst(alertDevice, 'ON')
            self.log.info('You should be able to hear the sirens now...')
        else:
            self.log.info('ALARM_TEST_MODE is activated. No sirens!')
        postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Alert_Max_Timer',
                             'ON')
Example #4
0
 def countOpenSections(self):
     '''
     A sensor has changed its state. We are here to calculate 
     how many open sensors there are in the zone at this very moment.
     Saves the result in self.openSections and returns it.
     WE DO NOT INCLUDE MOTION DETECTORS IN THE COUNT UNLESS ARMED AWAY!
     E.G. Those sensors that belongs to group 'G_Motion'
     '''
     self.openSections = 0
     for sensor in self.sensors:
         #self.log.debug('Checking sensor: '+sensor.name+'. : '+ str(sensor.isEnabled() and sensor.isActive()))
         if sensor.isEnabled() and sensor.isActive() \
         and ('G_Motion' not in itemRegistry.getItem(sensor.name).groupNames or self.getArmingMode() in [ARMINGMODE['ARMED_AWAY']]):
             self.openSections += 1
             self.log.debug('Open sensor: ' + sensor.name)
     self.log.debug('Number of open sections in ' +
                    self.name.decode('utf-8') + ' is: ' +
                    str(self.openSections))
     postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Open_Sections',
                          self.openSections)
     return self.openSections
Example #5
0
 def getNagSensors(self, timerTimedOut=False):
     '''
     Check if nagging is required. Performed when a sensor changes its state and when the nag timer ends.
     Nagging is only performed when a zone is disarmed.
     '''
     nagSensors = []
     for sensor in self.sensors:
         if sensor.isEnabled() and sensor.isActive(
         ) and sensor.nag and self.getArmingMode(
         ) == ARMINGMODE['DISARMED']:
             nagSensors.append(sensor)
     if len(nagSensors) == 0:
         postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Nag_Timer',
                              'OFF')  # Cancel the nag timer
     else:
         postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Nag_Timer',
                              'ON')
         if timerTimedOut and 'onNagTimer' in dir(custom):
             self.log.debug('Calling custom onNagTimer function')
             custom.onNagTimer(self, nagSensors)
     return nagSensors
Example #6
0
    def setZoneStatus(self,
                      newZoneStatus,
                      sendCommand=False,
                      errorMessage=None):
        '''
        Sets the zones current status
        '''
        if newZoneStatus not in [
                ZONESTATUS['NORMAL'], ZONESTATUS['ALERT'], ZONESTATUS['ERROR'],
                ZONESTATUS['TRIPPED'], ZONESTATUS['ARMING']
        ]:
            raise IdeAlarmError('Trying to set an invalid zone status')
        oldZoneStatus = self._zoneStatus
        self._zoneStatus = newZoneStatus

        if newZoneStatus in [ZONESTATUS['NORMAL']]:

            # Cancel all timers so they won't fire
            postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Entry_Timer',
                                 'OFF')
            postUpdateCheckFirst('Z' + str(self.zoneNumber) + '_Exit_Timer',
                                 'OFF')
            postUpdateCheckFirst(
                'Z' + str(self.zoneNumber) + '_Alert_Max_Timer', 'OFF')

            # Cancel sirens
            for alertDevice in self.alertDevices:
                sendCommandCheckFirst(alertDevice, 'OFF')

        # Sync the Zone Status Item
        postUpdateCheckFirst(self.statusItem, newZoneStatus, sendCommand)

        # Call custom function if available
        if 'onZoneStatusChange' in dir(custom):
            custom.onZoneStatusChange(self,
                                      newZoneStatus,
                                      oldZoneStatus,
                                      errorMessage=errorMessage)