Exemplo n.º 1
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))
Exemplo n.º 2
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
Exemplo n.º 3
0
    def _get_intent_config(self, context: ExecutionContext):

        intent_configs = self.get_intent_configs()

        intent = context.get_intent()

        if intent in intent_configs:
            return intent_configs[intent]
        return None
Exemplo n.º 4
0
    def __epg_current_channel(self, context: ExecutionContext):

        channel_number = context.get_slot_id('channel')

        channel_name = context.get_slot_value('channel')

        program = self.epg_service.get_current_programs_by_channel(channel_number)

        if program is None:
            return Sentences.NO_EPG_CHANNEL % channel_name

        program_result = program.title

        if program.sub_title is not None:
            program_result += "," + program.sub_title

        if program.description is not None:
            program_result += ",," + program.description

        return Sentences.EPG_CHANNEL % (channel_name, program_result)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def process_request(self, alexa_request) -> AlexaResponse:

        alexa_type = alexa_request.get_request_type()
        # S'il n'y a pas de type de request, c'est une erreur
        if alexa_type is None:
            return AlexaResponse(Sentences.ERROR, True)

        # Si Alexa notifie la fin de la session, on fait rien
        if alexa_type == EglantineConstants.END_SESSION_REQUEST_TYPE:
            return AlexaResponse(Sentences.NOTHING, True)

        # S'il n'y a pas de phrase fournie par Alexa, c'est une erreur
        alexa_intent = alexa_request.get_intent()
        if alexa_intent is None:
            return AlexaResponse(Sentences.ERROR, True)

        # Lancement de la skill, la skill se présente
        if alexa_intent == EglantineConstants.LAUNCH_INTENT:
            return AlexaResponse(Sentences.LAUNCH_PROMPT, False)

        # Traitement de la requête demandée
        thread_service = self.__get_current_service(alexa_request)

        # S'il y a un service précédemment non terminé et que l'on dit "OK"
        if thread_service is not None and alexa_intent == EglantineConstants.OK_INTENT:

            alexa_response = AlexaResponse()

            # On attend le service à nouveau
            self.__wait_result(alexa_request, alexa_response, thread_service)

            return alexa_response

        # S'il y a service précédemment non terminé, qu'il tourne toujours et que l'on dit autre chose que "OK", on demande d'attendre
        if thread_service is not None and thread_service.isAlive():
            return AlexaResponse(Sentences.BUSY, True)

        # S'il n'y a pas ou plus de Thread en cours, on execute la requete demandée
        execution_context = ExecutionContext(alexa_intent,
                                             alexa_request.get_slots(),
                                             self.__get_session(alexa_request))

        alexa_response = AlexaResponse()

        has_candidate = self.process_candidate_service(alexa_request,
                                                       alexa_response,
                                                       execution_context)

        if not has_candidate:
            alexa_response.set_sentence(Sentences.UNKNOWN)
            alexa_response.set_end_session(False)

        return alexa_response
Exemplo n.º 7
0
    def __watch_movie(self, context: ExecutionContext):

        queryMovie = context.get_slot_value('queryMovie')

        movie = self.__find_movie(queryMovie)

        if movie is None:
            return Sentences.MOVIE_NOT_FOUND % (queryMovie)

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

        self._remote(room).set_input(self._kodi_input)

        response = self._kodi.Player.Open(
            {"item": {
                "movieid": movie['movieid']
            }})

        if self.__check_result(response):
            return Sentences.MOVIE_FOUND % (movie['label'])
        else:
            return Sentences.MOVIE_ERROR_STARTED % (movie['label'])
Exemplo n.º 8
0
    def __listen_track(self, context: ExecutionContext):

        room = self._get_room(context)

        query_track = context.get_slot_value('queryTrack')

        query_artist = context.get_slot_value('queryArtist')

        if query_artist is None:
            query = query_track
        else:
            query = query_track + " " + query_artist

        logging.info('LISTEN TRACK %s in %s' % (query, room))

        self._process_rooms(context)

        result_search = self._remote(room).search_play(query, 'tracks', 'deezer')

        if result_search is not None:
            return Sentences.TRACK_FOUND % (
                result_search['track'], result_search['artist'], self.__get_music_location(context))
        else:
            return Sentences.TRACK_NOT_FOUND % query_track
Exemplo n.º 9
0
    def __listen_album(self, context: ExecutionContext):

        room = self._get_room(context)

        query_album = context.get_slot_value('queryAlbum')

        query_artist = context.get_slot_value('queryArtist')

        if query_artist is None:
            query = query_album
        else:
            query = query_album + " " + query_artist

        logging.info('LISTEN ALBUM %s in %s' % (query, room))

        self._process_rooms(context)

        result_search = self._remote(room).search_play(query, 'albums', 'deezer')

        if result_search is not None:
            return Sentences.ALBUM_FOUND % (
                result_search['album'], result_search['artist'], self.__get_music_location(context))
        else:
            return Sentences.ALBUM_NOT_FOUND % query_album
Exemplo n.º 10
0
    def __listen_radio(self, context: ExecutionContext):

        room = self._get_room(context)

        query = simplify_accronym(context.get_slot_value('queryRadio'))

        logging.info('LISTEN RADIO %s in %s' % (query, room))

        self._process_rooms(context)

        result_search = self._remote(room).play_radio(query)

        if result_search is not None:
            return Sentences.RADIO_FOUND % (result_search, self.__get_music_location(context))
        else:
            return Sentences.RADIO_NOT_FOUND % (query, self.__get_music_location(context))
Exemplo n.º 11
0
    def __listen_artist(self, context: ExecutionContext):

        room = self._get_room(context)

        query = context.get_slot_value('queryArtist')

        logging.info('LISTEN ARTIST %s in %s' % (query, room))

        self._process_rooms(context)

        result_search = self._remote(room).search_play(query, 'artists', 'deezer')

        if result_search is not None:
            return Sentences.ARTIST_FOUND % (result_search['artist'], self.__get_music_location(context))
        else:
            return Sentences.ARTIST_NOT_FOUND % query
Exemplo n.º 12
0
    def _increase_volume(self, context: ExecutionContext):

        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('INCREASE VOLUME (%s)' % (room))
                remote.increase_volume()

        else:
            remote = self._remote(room)
            remote.turn_on()
            logging.info('INCREASE VOLUME (%s)' % (room))
            remote.increase_volume()

        return None
Exemplo n.º 13
0
    def _check_config(self, context: ExecutionContext) -> bool:

        intent_config = self._get_intent_config(context)

        if 'expected-slots' in intent_config:

            expected_slots = intent_config['expected-slots']

            for expected_slot_name in expected_slots:

                input_slot: Slot = context.get_slot(expected_slot_name)
                if input_slot is None:
                    return False

                expected_slot = expected_slots[expected_slot_name]
                if expected_slot is None:
                    return True

                if isinstance(expected_slot, list):
                    return self.__has_expected_slot(input_slot, expected_slot)
                elif not self.__is_expected_slot(input_slot, expected_slot):
                    return False

        return True
Exemplo n.º 14
0
 def _is_multiroom(self, context: ExecutionContext):
     return context.get_slot_id(
         'multiroom', False) or (self._is_current_multiroom(context)
                                 and context.get_slot_id('room') is None)
Exemplo n.º 15
0
 def _get_room(self, context: ExecutionContext):
     return context.get_slot_id('room', self._get_current_room(context))
Exemplo n.º 16
0
 def _set_current_room(self, context: ExecutionContext, current_room: str):
     return context.get_session().set_attribute('musiccast.room',
                                                current_room)
Exemplo n.º 17
0
 def _get_current_room(self, context: ExecutionContext):
     return context.get_session().get_attribute('musiccast.room',
                                                self._get_default_room())
Exemplo n.º 18
0
 def _set_current_multiroom(self, context: ExecutionContext,
                            current_multi_room: bool):
     context.get_session().set_attribute('musiccast.multiroom',
                                         current_multi_room)
Exemplo n.º 19
0
 def _is_current_multiroom(self, context: ExecutionContext):
     return context.get_session().get_attribute('musiccast.multiroom',
                                                False)
Exemplo n.º 20
0
    def __watch_photo_album(self, context: ExecutionContext):
        photo_album = context.get_slot_id('photoAlbum')

        logging.info('WATCH PHOTO ALBUM: %s ' % photo_album)

        return "Regardons l'album photo %s " % photo_album
Exemplo n.º 21
0
    def __watch_movie(self, context: ExecutionContext):
        movie = context.get_slot_id('movie')

        logging.info('WATCH MOVIE: %s ' % movie)

        return "Ok, je mets le film %s " % movie