def onNagTimer(zone, nagSensors): ''' You should do something about the open doors! ''' sdf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss") logMsg = '' msg = '' for i in range(len(nagSensors)): sensor = nagSensors[i] msg += sensor.label logMsg += sensor.label logMsg += u' opened ' + sdf.print(sensor.getLastUpdate()) if i + 2 == len(nagSensors): msg += ' and ' logMsg += ' and ' elif i + 1 == len(nagSensors): msg += '.' logMsg += '.' elif i + 2 < len(nagSensors): msg += ', ' logMsg += ', ' msg = u'Open sections in ' + zone.name.decode('utf-8') + '. ' + msg log.info(msg) if zone.zoneNumber in [ 1, 3, 4 ] and itemRegistry.getItem('Z1_Block_Nag_Timer').state != ON: tts(msg, PRIO['HIGH']) elif zone.zoneNumber == 2 and itemRegistry.getItem( 'Z2_Block_Nag').state != ON: tts(msg, PRIO['MODERATE'])
def getLastUpdate(self): ''' Returns the sensors last update time (if available). type is 'org.joda.time.DateTime', http://joda-time.sourceforge.net/apidocs/org/joda/time/DateTime.html ''' try: lastUpdate = PersistenceExtensions.lastUpdate( itemRegistry.getItem(self.name)).toDateTime() except: lastUpdate = DateTime(0) self.log.info('Could not retrieve persistence data for sensor: ' + self.name.decode('utf8')) return lastUpdate
def __init__(self, parent, cfg): ''' Initialise the IdeAlarmSensor class Expects: - Parent object - cfg (dictionary) The sensor's configuration dictionary ''' self.name = cfg['name'] _label = itemRegistry.getItem(self.name).label self.label = _label if _label is not None else 'Sensor has no label' self.parent = weakref.ref(parent) # <= garbage-collector safe! self.sensorClass = cfg['sensorClass'] self.nag = cfg['nag'] self.nagTimeoutMins = cfg['nagTimeoutMins'] self.armWarn = cfg['armWarn'] self.enabled = cfg['enabled'] self.log = logging.getLogger(LOG_PREFIX + '.IdeAlarmSensor.' + self.name.decode('utf8'))
def sayHello(): hour = DateTime.now().getHourOfDay() if not (hour > 7 and hour < 22): return greetings = [greeting(), 'Hello', 'Greetings', 'Hi'] peopleAtHome = [] for member in itemRegistry.getItem('G_Presence_Family').getAllMembers(): if member.state.toString() == 'OPEN': peopleAtHome.append(member.label) random.shuffle(peopleAtHome) msg = random.choice(greetings) for i in range(len(peopleAtHome)): person = peopleAtHome[i] msg += ' ' + person if i + 2 == len(peopleAtHome): msg += ' and' elif i + 1 == len(peopleAtHome): msg += '.' elif i + 2 < len(peopleAtHome): msg += ',' tts(msg)
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
def isActive(self): ''' The sensor is considered active when its OPEN, ON or NULL. Locks are different. ''' return isActive(itemRegistry.getItem(self.name))