Exemplo n.º 1
0
def test_device_command_reboot():
    api_instance = esperclient.CommandsApi(esperclient.ApiClient(configuration))
    command = esperclient.CommandRequest(command='REBOOT')
    try:
        api_response = api_instance.run_command(enterprise_id, device_id, command)
        #print(api_response)
    except ApiException as e:
        print("Exception when calling CommandsApi->run_command: %s\n" % e)

    assert api_response.id is not None, "Id cannot be None"
    assert api_response.state == 'Command Initiated', "Command could not be initiated"
Exemplo n.º 2
0
def test_device_command_status_get():
    api_instance = esperclient.CommandsApi(esperclient.ApiClient(configuration))
    command_id = '0fd65c8a-a015-4695-a7b6-6f79c75887df'  # replace with valid uuid
    device_id = 'cd2d9e4b-953c-482f-abbc-168910851bad'  # replace with valid uuid

    try:
        api_response = api_instance.get_command(command_id, device_id, enterprise_id)
        #print(api_response)
    except ApiException as e:
        print("Exception when calling CommandsApi->get_command: %s\n" % e)

    assert api_response.id is not None, "Id cannot be None"
Exemplo n.º 3
0
def test_device_command_settings_change():
    api_instance = esperclient.CommandsApi(esperclient.ApiClient(configuration))
    command_args = esperclient.CommandArgs(brightness_value=100)
    command = esperclient.CommandRequest(command='SET_BRIGHTNESS_SCALE', command_args=command_args)
    try:
        api_response = api_instance.run_command(enterprise_id, device_id, command)
        # print(api_response)
    except ApiException as e:
        print("Exception when calling CommandsApi->run_command: %s\n" % e)

    assert api_response.id is not None, "Id cannot be None"
    assert api_response.state == 'Command Initiated', "Command could not be initiated"
Exemplo n.º 4
0
def test_device_app_deploy():
    api_instance = esperclient.CommandsApi(esperclient.ApiClient(configuration))
    command_args = esperclient.CommandArgs(app_version='2f81b955-4a30-4b1b-a99f-b4016ba24854')  # replace with valid uuid
    command = esperclient.CommandRequest(command='INSTALL', command_args=command_args)
    try:
        api_response = api_instance.run_command(enterprise_id, device_id, command)
        #print(api_response)
    except ApiException as e:
        print("Exception when calling CommandsApi->run_command: %s\n" % e)

    assert api_response.id is not None, "Id cannot be None"
    assert api_response.state == 'Command Initiated', "Command could not be initiated"
Exemplo n.º 5
0
def run_whitelist_command(device, package_name):
    api_instance = esperclient.CommandsApi(
        esperclient.ApiClient(CONFIGURATION))
    command_args = esperclient.CommandArgs(package_name=package_name)
    command = esperclient.CommandRequest(command='ADD_TO_WHITELIST',
                                         command_args=command_args)
    try:
        api_response = api_instance.run_command(ENTERPRISE_ID, device.id,
                                                command)

        if api_response.id is not None:
            print('Whitelist command fired successfully on {} for {}'.format(
                device.device_name, package_name))
    except ApiException as api_exception:
        print("Exception when calling CommandsApi->run_command: %s\n" %
              api_exception)
Exemplo n.º 6
0
def run_uninstall_command(device, package_name, app_id):
    api_instance = esperclient.CommandsApi(
        esperclient.ApiClient(CONFIGURATION))
    command_args = esperclient.CommandArgs(package_name=package_name,
                                           app_version=app_id)
    command = esperclient.CommandRequest(command='UNINSTALL',
                                         command_args=command_args)
    try:
        api_response = api_instance.run_command(ENTERPRISE_ID, device.id,
                                                command)
        if api_response.id is not None:
            print('Uninstall command fired successfully on ' + device.device_name +\
                                                            ' for ' + package_name)
    except ApiException as api_exception:
        print("Exception when calling CommandsApi->run_command: %s\n" %
              api_exception)
Exemplo n.º 7
0
def change_device_settings(command, value):
    if command == "brightness":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            if int(value) > 100 or int(value) < 0:
                print("Brightness value has to be in between 0-100")
                sys.exit(1)

            command_args = esperclient.CommandArgs(brightness_value=int(value))
            command = esperclient.CommandRequest(
                command='SET_BRIGHTNESS_SCALE', command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('brightness command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "alarm_volume":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            if int(value) > 100 or int(value) < 0:
                print("Alarm volume value has to be in between 0-100")
                sys.exit(1)

            command_args = esperclient.CommandArgs(volume_level=int(value),
                                                   stream=int(2))
            command = esperclient.CommandRequest(command='SET_STREAM_VOLUME',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print(
                        'alarm volume change command fired successfully on ' +
                        device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "ring_volume":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            if int(value) > 100 or int(value) < 0:
                print("Ring volume value has to be in between 0-100")
                sys.exit(1)

            command_args = esperclient.CommandArgs(volume_level=int(value),
                                                   stream=int(0))
            command = esperclient.CommandRequest(command='SET_STREAM_VOLUME',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('Ring volume change command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "notification_volume":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            if int(value) > 100 or int(value) < 0:
                print("Notification volume value has to be in between 0-100")
                sys.exit(1)

            command_args = esperclient.CommandArgs(volume_level=int(value),
                                                   stream=int(1))
            command = esperclient.CommandRequest(command='SET_STREAM_VOLUME',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print(
                        'Notification volume change command fired successfully on '
                        + device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "music_volume":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            if int(value) > 100 or int(value) < 0:
                print("Music volume value has to be in between 0-100")
                sys.exit(1)

            command_args = esperclient.CommandArgs(volume_level=int(value),
                                                   stream=int(3))
            command = esperclient.CommandRequest(command='SET_STREAM_VOLUME',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print(
                        'Music volume change command fired successfully on ' +
                        device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "bluetooth":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            command_args = esperclient.CommandArgs(bluetooth_state=value)
            command = esperclient.CommandRequest(command='SET_BLUETOOTH_STATE',
                                                 command_args=command_args)
            # print(command)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('Bluetooth change command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "wifi":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            command_args = esperclient.CommandArgs(wifi_state=value)
            command = esperclient.CommandRequest(command='SET_WIFI_STATE',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('Wifi change command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "gps":
        for device in ACTIVE_DEVICE_LIST:
            if value == "off":
                state = 0
            elif value == "sensors_only":
                state = 1
            elif value == "battery_saving":
                state = 2
            elif value == "high":
                state = 3
            else:
                print(
                    "Invalid GPS state: Valid states are: off, high, sensors_only"
                    "and battery_saving")
                sys.exit(1)

            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            command_args = esperclient.CommandArgs(gps_state=int(state))
            command = esperclient.CommandRequest(command='SET_GPS_STATE',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('GPS change command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "ping":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            command_args = esperclient.CommandArgs()
            command = esperclient.CommandRequest(command='UPDATE_HEARTBEAT',
                                                 command_args=command_args)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('UPDATE_HEARTBEAT command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)

    elif command == "reboot":
        for device in ACTIVE_DEVICE_LIST:
            api_instance = esperclient.CommandsApi(
                esperclient.ApiClient(CONFIGURATION))
            command_args = esperclient.CommandArgs()
            command = esperclient.CommandRequest(command='REBOOT',
                                                 command_args=command_args)
            # print(command)
            try:
                api_response = api_instance.run_command(
                    ENTERPRISE_ID, device.id, command)
                if api_response.id is not None:
                    print('Reboot command fired successfully on ' +
                          device.device_name)
            except ApiException as api_exception:
                print("Exception when calling CommandsApi->run_command: %s\n" %
                      api_exception)
Exemplo n.º 8
0
 def get_command_api_client(self):
     return client.CommandsApi(client.ApiClient(self.config))