def setUp(self): self.action = AlertOnHumidityOutOfRange(35, 50, 3) self.zone1 = Zone('great room', [], Level.FIRST_FLOOR).addDevice(HumiditySensor(ITEMS[0])) AlertManager._setTestMode(True) AlertManager.reset() cast_manager._setTestMode(True)
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)
def setUp(self): self.zone1 = Zone.createExternalZone('porch').addDevice(Door(ITEMS[0])) self.zone2 = Zone.createExternalZone('garage').addDevice(Door( ITEMS[1])) AlertManager._setTestMode(True) AlertManager.reset()
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
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
def setUp(self): self.action = AlertOnTemperatureOutOfRange(35, 50, 3) self.zone1 = Zone('great room').addDevice(TemperatureSensor(ITEMS[0])) AlertManager._setTestMode(True) AlertManager.reset() cast_manager._setTestMode(True)
def sendEventAndAssertAlertContainMessage(self, message): AlertManager.reset() eventInfo = EventInfo(ZoneEvent.HUMIDITY_CHANGED, ITEMS[0], self.zone1, None, self.getMockedEventDispatcher()) value = self.action.onAction(eventInfo) self.assertTrue(value) self.assertTrue(message in AlertManager._lastEmailedSubject)
def sendEventAndAssertNoAlert(self): AlertManager.reset() eventInfo = EventInfo(ZoneEvent.HUMIDITY_CHANGED, ITEMS[0], self.zone1, None, self.getMockedEventDispatcher()) value = self.action.onAction(eventInfo) self.assertTrue(value) self.assertEqual(None, AlertManager._lastEmailedSubject)
def setUp(self): self.action = AlertOnHighGasLevel() self.zone1 = Zone('great room', [], Level.FIRST_FLOOR).addDevice( SmokeSensor(ITEMS[1], ITEMS[0])) # index reverse order intentionally ITEMS[0].setState(scope.OnOffType.OFF) AlertManager._setTestMode(True) AlertManager.reset() cast_manager._setTestMode(True)
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 setUp(self): super(ArmAfterFrontDoorClosedTest, self).setUp() self.alarmPartition = AlarmPartition(ITEMS[2], ITEMS[3]) self.externalMotionSensor = MotionSensor(ITEMS[4]) self.internalMotionSensor = MotionSensor(ITEMS[5]) self.zone1 = Zone.createExternalZone('porch') \ .addDevice(Door(ITEMS[0])) \ .addDevice(self.externalMotionSensor) self.zone2 = Zone('foyer', [self.internalMotionSensor, self.alarmPartition]) self.mockZoneManager= MockZoneManager(self.alarmPartition, [self.zone1, self.zone2]) AlertManager._setTestMode(True) AlertManager.reset()
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))
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
def sendAlert(): msg = 'The {} door has been opened for {} minutes.'.format( zone.getName(), self.maxElapsedTimeInSeconds / 60) alert = Alert.createWarningAlert(msg) AlertManager.processAlert(alert, zoneManager)
def tearDown(self): AlertManager._setTestMode(False) super(ArmAfterFrontDoorClosedTest, self).tearDown()
def tearDown(self): AlertManager._setTestMode(False)
def tearDown(self): cast_manager._setTestMode(False) AlertManager._setTestMode(False)