Esempio n. 1
0
def test_mute_method_performs_correct_api_query(mocked_requests,
                                                connected_device):
    transport_service = NodeDeviceTransportControlService()

    transport_service.mute(connected_device)

    mocked_requests.get.assert_called_with(
        transport_service._generate_mute_query(connected_device.name))
Esempio n. 2
0
def test_volume_up_method_performs_correct_api_query(mocked_requests,
                                                     connected_device):
    transport_service = NodeDeviceTransportControlService()
    volume_increment = VolumeUpUseCase.DEFAULT_VOLUME_INCREMENT

    connected_device.increase_volume(volume_increment)
    transport_service.volume_up(connected_device)

    mocked_requests.get.assert_called_with(
        transport_service._generate_volume_query(connected_device.name,
                                                 connected_device.volume))
Esempio n. 3
0
def test_volume_up_method_failure_raises_exception(mocked_requests,
                                                   connected_device):
    transport_service = NodeDeviceTransportControlService()

    mocked_response_object = mock.create_autospec(requests.Response)
    mocked_response_object.ok = False

    mocked_requests.get.return_value = mocked_response_object

    with pytest.raises(NoReachableDeviceException):
        transport_service.mute(connected_device)
Esempio n. 4
0
def test_generate_url_query_for_mute(connected_device):
    PROTOCOL = NodeDeviceTransportControlService.PROTOCOL
    HOST = NodeDeviceTransportControlService.HOST
    PORT = NodeDeviceTransportControlService.PORT

    room_name = connected_device.name
    volume_level = 10

    transport_service = NodeDeviceTransportControlService()

    assert transport_service._generate_mute_query(
        room_name) == "http://localhost:5005/Antho/mute"
Esempio n. 5
0
def test_volume_up_method_failure_raises_exception(mocked_requests,
                                                   connected_device):
    transport_service = NodeDeviceTransportControlService()
    volume_increment = VolumeUpUseCase.DEFAULT_VOLUME_INCREMENT

    connected_device.increase_volume(volume_increment)
    mocked_response_object = mock.create_autospec(requests.Response)
    mocked_response_object.ok = False

    mocked_requests.get.return_value = mocked_response_object

    with pytest.raises(NoReachableDeviceException):
        transport_service.volume_up(connected_device)
Esempio n. 6
0
    logging.info(play_music_request)
    response = use_case.execute(play_music_request)

    if not response:
        hermes.publish_end_session(intentMessage.session_id, FR_TTS_SHORT_ERROR)
    else:
        hermes.publish_end_session(intentMessage.session_id, response.feedback)

if __name__ == "__main__":
    configuration = read_configuration_file("config.ini")
    client_id = configuration['secret']['client_id']
    client_secret = configuration['secret']['client_secret']

    with Hermes(HERMES_HOST) as h:
        h.device_discovery_service = NodeDeviceDiscoveryService()
        h.device_transport_control_service = NodeDeviceTransportControlService()
        h.music_search_service = SpotifyMusicSearchService(client_id, client_secret)
        h.music_playback_service = NodeMusicPlaybackService()

        h \
            .subscribe_session_started(hotword_detected_callack) \
            .subscribe_intent("playMusic4", playMusic_callback) \
            .subscribe_intent("volumeUp4", volumeUp_callback) \
            .subscribe_intent("volumeDown4", volumeDown_callback) \
            .subscribe_intent("volumeSet4", volumeSet_callback) \
            .subscribe_intent("muteSound4", mute_callback) \
            .subscribe_intent("resumeMusic4", resumeMusic_callback) \
            .subscribe_intent("speakerInterrupt4", speakerInterrupt_callback) \
            .subscribe_intent("nextSong4", nextSong_callback) \
            .loop_forever()
Esempio n. 7
0
def test_transport_control_service_initialization():
    transport_service = NodeDeviceTransportControlService()

    assert transport_service.PORT == NodeDeviceTransportControlService.PORT
    assert transport_service.HOST == NodeDeviceTransportControlService.HOST
    assert transport_service.PROTOCOL == NodeDeviceTransportControlService.PROTOCOL