示例#1
0
    def testPlayMessage_volumeAboveThreshold_throwsException(self):
        with self.assertRaises(ValueError) as cm:
            cast_manager.playMessage(TEST_MESSAGE, cast_manager.getAllCasts(),
                                     101)

        self.assertEqual('volume must be between 0 and 100',
                         cm.exception.args[0])
    def testProcessAlert_criticalAlert_returnsTrue(self):
        alert = Alert.createCriticalAlert(SUBJECT)
        result = AlertManager.processAlert(alert)
        self.assertTrue(result)

        casts = cast_manager.getAllCasts()
        for cast in casts:
            self.assertEqual(SUBJECT, cast.getLastTtsMessage())
示例#3
0
    def testGetAllCasts_noParams_returnsNormally(self):
        casts = cast_manager.getAllCasts()
        self.assertTrue(len(casts) > 0)

        for cast in casts:
            self.assertTrue(cast.getPlayerName() in scope.items)
            self.assertTrue(cast.getVolumeName() in scope.items)
            self.assertTrue(cast.getIdleItemName() in scope.items)
    def testProcessAlert_audioWarningAlert_returnsTrue(self):
        alert = Alert.createAudioWarningAlert(SUBJECT)
        result = AlertManager.processAlert(alert)
        self.assertTrue(result)

        casts = cast_manager.getAllCasts()
        for cast in casts:
            self.assertEqual(SUBJECT, cast.getLastTtsMessage())

        self.assertEqual(None, AlertManager._lastEmailedSubject)
示例#5
0
    def processAlert(alert, zoneManager=None):
        '''
        Processes the provided alert.
        If the alert's level is WARNING or CRITICAL, the TTS subject will be played
        on the ChromeCasts.

        :param Alert alert: the alert to be processed
        :param ImmutableZoneManager zoneManager: used to retrieve the ActivityTimes
        :return: True if alert was processed; False otherwise.
        :raise: ValueError if alert is None
        '''

        if None == alert:
            raise ValueError('Invalid alert.')

        PE.logInfo(u"Processing alert\n{}".format(alert.toString()))

        if AlertManager._isThrottled(alert):
            return False

        if not alert.isAudioAlertOnly():
            AlertManager._emailAlert(alert,
                                     AlertManager._getOwnerEmailAddresses())

        # Play an audio message if the alert is warning or critical.
        # Determine the volume based on the current zone activity.
        volume = 0
        if alert.isCriticalLevel():
            volume = 60
        elif alert.isWarningLevel():
            if None == zoneManager:
                volume = 60
            else:
                activity = zoneManager.getDevicesByType(ActivityTimes)[0]
                if activity.isSleepTime():
                    volume = 0
                elif activity.isQuietTime():
                    volume = 40
                else:
                    volume = 60

        if volume > 0:
            casts = cast_manager.getAllCasts()
            cast_manager.playMessage(alert.getSubject(), casts, volume)

        return True
示例#6
0
 def testFindCasts_firstItemPrefix_returnsOne(self):
     casts = cast_manager.getAllCasts()
     result = cast_manager.findCasts(casts[0].getPrefix())
     self.assertEqual(1, len(result))
     self.assertEqual(casts[0], result[0])
示例#7
0
 def testFindCasts_undef_returnsAll(self):
     casts = cast_manager.getAllCasts()
     result = cast_manager.findCasts(scope.UnDefType.UNDEF)
     self.assertEqual(len(casts), len(result))
示例#8
0
 def testFindCasts_allStringType_returnsAll(self):
     casts = cast_manager.getAllCasts()
     result = cast_manager.findCasts(scope.StringType("ALL"))
     self.assertEqual(len(casts), len(result))
示例#9
0
 def testFindCasts_all_returnsAll(self):
     casts = cast_manager.getAllCasts()
     result = cast_manager.findCasts("ALL")
     self.assertEqual(len(casts), len(result))