Esempio n. 1
0
def test_unmute_location_unmutes_location():
    lm = LocationManager()
    lm.toggle_mute('kitchen', True)
    loc = lm.get_location('kitchen')
    assert loc.is_muted
    lm.toggle_mute('kitchen', False)
    loc = lm.get_location('kitchen')
    assert not loc.is_muted
Esempio n. 2
0
def speak(person_name, location_name, ignore_motion, ignore_confirmation,
          voice_id, no_audio, simulate, fail_confirm):
    try:
        while True:
            click.echo("Checking for messages . . .")

            lm = LocationManager()
            loc = lm.get_location(location_name)
            if not ignore_motion and not loc.is_motion:
                print 'Exiting. No motion detected at ' + location_name
                exit(1)
            speaker = Speaker(NoAudio=no_audio)
            message_manager = MessageManager(LocationName=location_name)
            click.echo('getting files')
            cache_manager = CacheManager(BucketName='pollexy-media',
                                         CacheName='chimes')
            cache_manager.sync_remote_folder()
            print 'Writing speech'
            vid, speech = message_manager.write_speech(PersonName=person_name)
            if vid:
                voice_id = vid
            if not speech:
                print "I have nothing to say"
                message_manager.delete_sqs_msgs()
            else:
                print "Speech:\n\n%s" % speech
                try:
                    pm = PersonManager()
                    p = pm.get_person(person_name)
                    do_speech = True
                    if fail_confirm:
                        logging.warning("FORCE FAILING confirmation")
                        reason, do_speech = "NoResponse", False

                    elif not no_audio and p.require_physical_confirmation and \
                            not ignore_confirmation:
                        lv = LocationVerification(PersonName=person_name,
                                                  LocationName=location_name,
                                                  VoiceId=voice_id)
                        do_speech, retry_count, timeout = \
                            lv.verify_person_at_location(SpeechMethod=say)

                    if do_speech:
                        speaker = Speaker(NoAudio=no_audio)
                        speaker.generate_audio(Message=speech,
                                               TextType='ssml',
                                               VoiceId=voice_id)
                        speaker.speak(IncludeChime=True)
                        message_manager.succeed_speech(dont_delete=simulate)
                    else:
                        message_manager.fail_speech(Reason=reason)
                finally:
                    speaker.cleanup()

    except Exception as exc:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print repr(
            traceback.format_exception(exc_type, exc_value, exc_traceback))
        click.echo("Error: %s" % str(exc))
        exit(2)
Esempio n. 3
0
def location_delete(name):
    lm = LocationManager()
    loc = lm.get_location(name)
    if loc:
        lm.delete(Name=name)
        click.echo('Deleted location {}'.format(name))
    else:
        click.echo("Location {} does not exist".format(name))
Esempio n. 4
0
def test_saving_switch_saves_id():
    l = LocationAvailability(LocationName='kitchen')
    id = 'myswitch'
    l.with_switch(HardwareId=id, Color='Red', Name='Test', Style='Circle')
    lm = LocationManager()
    lm.update_input_capabilities(l)
    loc = lm.get_location('kitchen')
    assert id in loc.input_capabilities.keys()
Esempio n. 5
0
def test_db_window_set_with_muted_window_is_not_available():
    now_dt = arrow.get('2014-01-01T09:09:00.000-05:00')
    tw = TimeWindow(ical=ical_event, CompareDateTime=now_dt)
    l = LocationAvailability(LocationName='kitchen')
    l.add_window(tw)
    tw = TimeWindow(ical=ical_event, CompareDateTime=now_dt, IsMuted=True)
    l.add_window(tw)
    lm = LocationManager()
    lm.update_window_set(l)
    l = lm.get_location('kitchen')
    assert not l.is_available(dt=now_dt)
Esempio n. 6
0
def test_saving_window_set_saves_set():
    now_dt = arrow.get('2014-01-01T09:09:00.000-05:00')
    tw = TimeWindow(ical=ical_event, CompareDateTime=now_dt)
    la = LocationAvailability(LocationName='kitchen')
    la.add_window(tw)
    tw = TimeWindow(IsMuted=True, ical=ical_event, CompareDateTime=now_dt)
    la.add_window(tw)
    lm = LocationManager()
    lm.update_window_set(la)
    loc = lm.get_location('kitchen')
    assert loc.time_windows.count() == 2
Esempio n. 7
0
def speak(person_name,
          location_name,
          ignore_motion,
          ignore_confirmation,
          voice_id,
          no_audio,
          simulate,
          fail_confirm,
          verbose):
    log = logging.getLogger('PollexyCli')
    if verbose:
        os.environ['LOG_LEVEL'] = 'DEBUG'
        log.setLevel(logging.DEBUG)
    try:
        while True:
            lm = LocationManager()
            loc = lm.get_location(location_name)
            if not ignore_motion and not loc.is_motion:
                print 'Exiting. No motion detected at ' + location_name
                exit(1)
            speaker = Speaker(NoAudio=no_audio)
            message_manager = MessageManager(LocationName=location_name)
            bm = message_manager.get_messages(MessageType='Bot',
                                              PersonName=person_name)
            if bm and len(bm) > 0:
                log.debug('Bot count = {}'.format(len(bm)))
                for bot in bm:
                    username = str(uuid.uuid4())
                    try:
                        lp = LexPlayer(
                            BotNames=bot.bot_names,
                            Alias="$LATEST",
                            Username=username,
                            VoiceId=voice_id,
                            IceBreaker=bot.ice_breaker,
                            Introduction=bot.introduction,
                            NoAudio=no_audio,
                            BotsRequired=bot.required_bots)
                        while (not lp.is_done):
                            lp.get_user_input()
                    except Exception as e:
                        print 'Bot failed: {}'.format(e)
                        raise
                message_manager.succeed_messages(dont_delete=simulate)

            cache_manager = CacheManager(BucketName='pollexy-media',
                                         CacheName='chimes')
            cache_manager.sync_remote_folder()
            vid, speech = message_manager.write_speech(PersonName=person_name)
            if vid:
                voice_id = vid
            if not speech:
                message_manager.succeed_messages(dont_delete=simulate)
                message_manager.delete_sqs_msgs()
            else:
                try:
                    pm = PersonManager()
                    p = pm.get_person(person_name)
                    do_speech = True
                    if fail_confirm:
                        log.warn("FORCE FAILING confirmation")
                        reason, do_speech = "NoResponse", False

                    elif not no_audio and p.require_physical_confirmation and \
                            not ignore_confirmation:
                        lv = LocationVerification(PersonName=person_name,
                                                  LocationName=location_name,
                                                  VoiceId=voice_id)
                        do_speech, retry_count, timeout = \
                            lv.verify_person_at_location(SpeechMethod=say)
                    log.debug('do_speech={}'.format(bool(do_speech)))
                    if fail_confirm:
                        message_manager.fail_messages(Reason=reason)
                    else:
                        if do_speech:
                            log.debug('starting speech')
                            speaker = Speaker(NoAudio=no_audio)
                            speaker.generate_audio(Message=speech,
                                                   TextType='ssml',
                                                   VoiceId=voice_id)
                            speaker.speak(IncludeChime=True)
                        log.debug('Succeeding messages')
                        message_manager.succeed_messages(dont_delete=simulate)
                finally:
                    speaker.cleanup()

    except Exception as exc:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print repr(traceback.format_exception(exc_type, exc_value,
                   exc_traceback))
        click.echo("Error: %s" % str(exc))
        exit(2)