use of com.google.api.services.cloudiot.v1.model.ListDeviceStatesResponse in project java-docs-samples by GoogleCloudPlatform.
the class DeviceRegistryExample method getDeviceStates.
// [END iot_get_device]
// [START iot_get_device_state]
/**
* Retrieves device metadata from a registry. *
*/
public static List<DeviceState> getDeviceStates(String deviceId, String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException {
GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
final String devicePath = String.format("projects/%s/locations/%s/registries/%s/devices/%s", projectId, cloudRegion, registryName, deviceId);
System.out.println("Retrieving device states " + devicePath);
ListDeviceStatesResponse resp = service.projects().locations().registries().devices().states().list(devicePath).execute();
return resp.getDeviceStates();
}
Aggregations