示例#1
0
    def process_intent(self,
                       context: ExecutionContext) -> EglantineServiceResult:

        intent_config = self._get_intent_config(context)

        if 'complete-slots' in intent_config:
            context.add_slots(intent_config['complete-slots'])

        intent_function = self._get_intent_function(context)

        logging.info('PROCESS-INTENT - BEGIN - slots = %s' %
                     str(context.get_slots().to_json()))

        t0 = time.perf_counter()

        result_function = intent_function(context)

        if result_function is None:
            result_function = EglantineServiceResult(None, False)
        if isinstance(result_function, str):
            result_function = EglantineServiceResult(result_function)

        logging.info(
            'PROCESS-INTENT - END - %.1f - slots = %s' %
            ((time.perf_counter() - t0), str(context.get_slots().to_json())))

        logging.info('PROCESS-INTENT - RESULT="%s"' %
                     result_function.get_sentence())

        return result_function
示例#2
0
    def _change_volume(self, context: ExecutionContext):

        volume = context.get_slot_value('volume')

        if volume == '?':
            return EglantineServiceResult(None)

        volume = int(volume)

        if volume not in range(0, 101):
            return Sentences.VOLUME_RANGE

        multiroom = self._is_multiroom(
            context) and context.get_slot_id('room') is None

        room = self._get_room(context)

        if multiroom:
            for room in self.__yamaha_remote_factory.get_room_ids():
                remote = self._remote(room)
                remote.turn_on()
                logging.info('CHANGE VOLUME TO %s (%s)' % (volume, room))
                remote.set_volume(volume)

            return Sentences.VOLUME_MODIFICATION % volume
        else:
            remote = self._remote(room)
            remote.turn_on()
            logging.info('CHANGE VOLUME TO %s (%s)' % (volume, room))
            remote.set_volume(volume)

            return Sentences.VOLUME_MODIFICATION_WITH_LOCATION % (
                volume, self._get_room_name(room))
示例#3
0
 def run(self) -> None:
     try:
         self.__result = self.__service.process_intent(self.__context)
     except Exception as e:
         self.__result = EglantineServiceResult(Sentences.ERROR_SERVICE %
                                                self.__service.get_name())
         raise e
示例#4
0
    def __pause(self, context: ExecutionContext):

        room = self._get_room(context)

        self._remote(room).pause()

        self._set_current_room(context, room)

        return EglantineServiceResult(Sentences.PAUSE_MUSIC % self.__get_music_location(context))
示例#5
0
    def __next(self, context: ExecutionContext):

        room = self._get_room(context)

        self._remote(room).next_song()

        self._set_current_room(context, room)

        return EglantineServiceResult(None, False)
示例#6
0
    def __previous(self, context: ExecutionContext):

        room = self._get_room(context)

        remote = self._remote(room)
        remote.previous_song()
        remote.previous_song()

        self._set_current_room(context, room)

        return EglantineServiceResult(None, False)
示例#7
0
    def __change_channel(self, context: ExecutionContext):

        room = context.get_slot_id('room', self._get_default_room())

        channel = context.get_slot_id('channel')

        logging.info('CHANGE CHANNEL')

        self.samsung_tv_remote.ensure_up()

        self._remote(room).set_input(self._tv_input)

        if context.service_changed():
            self.__next_channel(context)
            self.__previous_channel(context)

        for digit in channel:
            self.samsung_tv_remote.send_key('KEY_' + digit)
            logging.info('sendKey KEY_' + digit)

        return EglantineServiceResult(Sentences.CHANGE_CHANNEL % channel, False)
示例#8
0
    def __return_direct(self, context: ExecutionContext):
        self.samsung_tv_remote.send_key('KEY_STOP')

        return EglantineServiceResult(Sentences.RETURN_TO_DIRECT)
示例#9
0
    def __pause(self, context: ExecutionContext):
        self.samsung_tv_remote.send_key('KEY_PAUSE')

        return EglantineServiceResult(Sentences.PAUSE_TV)
示例#10
0
    def __resume(self, context: ExecutionContext):
        self.samsung_tv_remote.send_key('KEY_PLAY')

        return EglantineServiceResult(Sentences.RESUME_TV)
示例#11
0
 def __stop(self, context: ExecutionContext):
     self.samsung_tv_remote.send_key('KEY_STOP')
     return EglantineServiceResult(Sentences.STOP_TV)
示例#12
0
 def __previous_channel(self, context: ExecutionContext):
     logging.info('PREVIOUS CHANNEL')
     self.samsung_tv_remote.send_key('KEY_CHDOWN')
     return EglantineServiceResult(None, False, "")
示例#13
0
 def __next_channel(self, context: ExecutionContext):
     logging.info('NEXT CHANNEL')
     self.samsung_tv_remote.send_key('KEY_CHUP')
     return EglantineServiceResult(None, False, "")