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));
}
});
}
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));
}
});
}
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());
}
Aggregations