Search in sources :

Example 1 with DeviceData

use of com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData in project mbed-cloud-sdk-java by ARMmbed.

the class DeviceDirectory method addDevice.

/**
 * Adds a device.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Device device = new Device();
 *     device.setId("015f4ac587f500000000000100100249");
 *     device.setName("QuickstartDevice");
 *     device.setDescription("Quick start device");
 *     device.setDeviceType("quickstart");
 *
 *     Device newDevice = deviceDirectoryApi.addDevice(device);
 *     System.out.println("New device state: " + newDevice.getState());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param device
 *            Device details.
 * @return added device.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Device addDevice(@NonNull Device device) throws MbedCloudException {
    checkNotNull(device, TAG_DEVICE);
    checkModelValidity(device, TAG_DEVICE);
    final Device finalDevice = device;
    return CloudCaller.call(this, "addDevice()", DeviceAdapter.getMapper(), new CloudCall<DeviceData>() {

        @Override
        public Call<DeviceData> call() {
            return endpoint.getDirectory().deviceCreate(DeviceAdapter.reverseMapAdd(finalDevice));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) DeviceData(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 2 with DeviceData

use of com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData in project mbed-cloud-sdk-java by ARMmbed.

the class DeviceDirectory method updateDevice.

/**
 * Updates a device.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *     Device device = new Device();
 *     String deviceId = "015f4ac587f500000000000100100249";
 *     device.setId(deviceId);
 *     device.setName("QuickstartDevice");
 *     device.setDescription("Updated quick start device");
 *     device.setDeviceType("quickstart");
 *
 *     Device newDevice = deviceDirectoryApi.updateDevice(device);
 *     System.out.println("Updated device description: " + newDevice.getDescription());
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param device
 *            Device details.
 * @return updated device.
 * @throws MbedCloudException
 *             if a problem occurred during request processing.
 */
@API
@Nullable
public Device updateDevice(@NonNull Device device) throws MbedCloudException {
    checkNotNull(device, TAG_DEVICE);
    checkNotNull(device.getId(), TAG_DEVICE_ID);
    checkModelValidity(device, TAG_DEVICE);
    final Device finalDevice = device;
    return CloudCaller.call(this, "updateDevice()", DeviceAdapter.getMapper(), new CloudCall<DeviceData>() {

        @Override
        public Call<DeviceData> call() {
            return endpoint.getDirectory().deviceUpdate(finalDevice.getId(), DeviceAdapter.reverseMapUpdate(finalDevice));
        }
    });
}
Also used : CloudCall(com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall) Call(retrofit2.Call) Device(com.arm.mbed.cloud.sdk.devicedirectory.model.Device) DeviceData(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData) API(com.arm.mbed.cloud.sdk.annotations.API) Nullable(com.arm.mbed.cloud.sdk.annotations.Nullable)

Example 3 with DeviceData

use of com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData in project mbed-cloud-sdk-java by ARMmbed.

the class DeviceAdapter method mapList.

/**
 * Maps a list of device data.
 *
 * @param list
 *            device page
 * @return a list of devices
 */
public static ListResponse<Device> mapList(DevicePage list) {
    final DevicePage deviceList = list;
    final RespList<DeviceData> respList = new RespList<DeviceData>() {

        @Override
        public Boolean getHasMore() {
            return (deviceList == null) ? null : deviceList.isHasMore();
        }

        @Override
        public Integer getTotalCount() {
            return (deviceList == null) ? null : deviceList.getTotalCount();
        }

        @Override
        public String getAfter() {
            return (deviceList == null) ? null : deviceList.getAfter();
        }

        @Override
        public Integer getLimit() {
            return (deviceList == null) ? null : deviceList.getLimit();
        }

        @Override
        public String getOrder() {
            return (deviceList == null) ? null : deviceList.getOrder().toString();
        }

        @Override
        public List<DeviceData> getData() {
            return (deviceList == null) ? null : deviceList.getData();
        }
    };
    return GenericAdapter.mapList(respList, getMapper());
}
Also used : DevicePage(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DevicePage) DeviceData(com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData) RespList(com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)

Aggregations

DeviceData (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DeviceData)3 API (com.arm.mbed.cloud.sdk.annotations.API)2 Nullable (com.arm.mbed.cloud.sdk.annotations.Nullable)2 CloudCall (com.arm.mbed.cloud.sdk.common.CloudCaller.CloudCall)2 Device (com.arm.mbed.cloud.sdk.devicedirectory.model.Device)2 Call (retrofit2.Call)2 RespList (com.arm.mbed.cloud.sdk.common.GenericAdapter.RespList)1 DevicePage (com.arm.mbed.cloud.sdk.internal.devicedirectory.model.DevicePage)1