def onArmingModeChange(zone, newArmingMode, oldArmingMode): ''' This function will be called when there is a change of arming mode for a zone. oldArmingMode is None when initializing. ''' if zone.zoneNumber == 1: if oldArmingMode is not None: Pushover.pushover( 'An Alarm Zone arming mode change for ' + zone.name + ' triggered, new value is: ' + kw(ARMINGMODE, newArmingMode), PUSHOVER_DEF_DEV, PUSHOVER_PRIO['NORMAL']) if newArmingMode == ARMINGMODE['DISARMED']: sendCommandCheckFirst('Alarm_Status_Indicator_1', 'OFF') sendCommandCheckFirst('Wall_Plug_Bedroom_Fan', 'OFF') sayHello() elif newArmingMode == ARMINGMODE['ARMED_HOME']: sendCommandCheckFirst('Wall_Plug_Bedroom_Fan', 'ON') if newArmingMode != ARMINGMODE['DISARMED']: sendCommandCheckFirst('Alarm_Status_Indicator_1', 'ON') log.debug('Custom function: onArmingModeChange: ' + zone.name.decode('utf-8') + ' ---> ' + kw(ARMINGMODE, newArmingMode))
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'])
def onZoneStatusChange(zone, newZoneStatus, oldZoneStatus, errorMessage=None): ''' This function will be called when there is a change of zone status. oldZoneStatus is None when initializing. ''' log.info('Custom function: onZoneStatusChange: ' + zone.name.decode('utf-8') + ' ---> ' + kw(ZONESTATUS, newZoneStatus)) if newZoneStatus == ZONESTATUS['ERROR']: errMes = 'Error when arming zone ' + zone.name.decode( 'utf-8') + ': ' + errorMessage log.error(errMes) Pushover.pushover(errMes, PUSHOVER_DEF_DEV, PUSHOVER_PRIO['HIGH']) elif newZoneStatus == ZONESTATUS['ALERT']: # Get all sensors that have been tripped since 2 minutes regardless of their current state # considering that an intruder might have closed a tripped door already when this is running mins = 2 openSensors = zone.getOpenSensors(mins) sdf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss") msg = '' for i in range(len(openSensors)): sensor = openSensors[i] msg += sensor.label msg += u' tripped ' + sdf.print(sensor.getLastUpdate()) if i + 2 == len(openSensors): msg += ' and ' elif i + 1 == len(openSensors): msg += '.' elif i + 2 < len(openSensors): msg += ', ' msg = u'Alarm in zone ' + zone.name.decode('utf-8') + '. ' + msg log.error(msg) if zone.alarmTestMode: log.info('ideAlarm in TESTING MODE') tts(msg, PRIO['EMERGENCY']) Pushover.pushover(msg, PUSHOVER_DEF_DEV, PUSHOVER_PRIO['NORMAL']) else: tts(msg, PRIO['EMERGENCY']) Pushover.pushover(msg, PUSHOVER_DEF_DEV, PUSHOVER_PRIO['EMERGENCY']) elif newZoneStatus == ZONESTATUS['TRIPPED']: if zone.zoneNumber == 1: alertText = u'Intrusion in ' + zone.name.decode('utf-8') tts(alertText, PRIO['EMERGENCY']) elif newZoneStatus == ZONESTATUS['ARMING']: if zone.zoneNumber == 1: tts('sad cat', PRIO['HIGH'])
def onToggleSwitch(self, item): ''' Called whenever an alarm arming mode toggle switch has been switched. ''' newArmingMode = None if item.name == self.armAwayToggleSwitch: if self.getArmingMode() in [ARMINGMODE['DISARMED']]: newArmingMode = ARMINGMODE['ARMED_AWAY'] else: newArmingMode = ARMINGMODE['DISARMED'] else: if self.getArmingMode() in [ARMINGMODE['DISARMED']]: newArmingMode = ARMINGMODE['ARMED_HOME'] else: newArmingMode = ARMINGMODE['DISARMED'] self.log.debug('Toggeling zone \'' + self.name.decode('utf-8') + '\' to new arming mode: ' + kw(ARMINGMODE, newArmingMode)) self.setArmingMode(newArmingMode)
def onArmingModeChange(zone, newArmingMode, oldArmingMode): ''' This function will be called when there is a change of arming mode for a zone. oldArmingMode is None when initializing. ''' if zone.zoneNumber == 1: if oldArmingMode is not None: pass if newArmingMode == ARMINGMODE['DISARMED']: pass elif newArmingMode == ARMINGMODE['ARMED_HOME']: pass if newArmingMode != ARMINGMODE['DISARMED']: pass log.debug('Custom function: onArmingModeChange: ' + zone.name.decode('utf-8') + ' ---> ' + kw(ARMINGMODE, newArmingMode))
def onZoneStatusChange(zone, newZoneStatus, oldZoneStatus, errorMessage=None): ''' This function will be called when there is a change of zone status. oldZoneStatus is None when initializing. ''' log.info('Custom function: onZoneStatusChange: ' + zone.name.decode('utf-8') + ' ---> ' + kw(ZONESTATUS, newZoneStatus)) if newZoneStatus == ZONESTATUS['ERROR']: pass elif newZoneStatus == ZONESTATUS['ALERT']: # Get all sensors that have been tripped since 2 minutes regardless of their current state # considering that an intruder might have closed a tripped door already when this is running if zone.alarmTestMode: pass else: pass elif newZoneStatus == ZONESTATUS['TRIPPED']: if zone.zoneNumber == 1: pass elif newZoneStatus == ZONESTATUS['ARMING']: if zone.zoneNumber == 1: pass