Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: add fieldMask for getDevice and listDevices (#436)
Browse files Browse the repository at this point in the history
* Add fieldMask for getDevice and listDevices
  • Loading branch information
gcseh authored Feb 5, 2021
1 parent 556920f commit a97ed10
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions samples/manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,34 @@ const listDevices = async (registryId, projectId, cloudRegion) => {
registryId
);

const [response] = await iotClient.listDevices({parent: parentName});
// See full list of device fields: https://cloud.google.com/iot/docs/reference/cloudiot/rest/v1/projects.locations.registries.devices
// Warning! Use snake_case field names.
const fieldMask = {
paths: [
'id',
'name',
'num_id',
'credentials',
'last_heartbeat_time',
'last_event_time',
'last_state_time',
'last_config_ack_time',
'last_config_send_time',
'blocked',
'last_error_time',
'last_error_status',
'config',
'state',
'log_level',
'metadata',
'gateway_config',
],
};

const [response] = await iotClient.listDevices({
parent: parentName,
fieldMask,
});
const devices = response;

if (devices.length > 0) {
Expand Down Expand Up @@ -620,7 +647,34 @@ const getDevice = async (deviceId, registryId, projectId, cloudRegion) => {
deviceId
);

const [response] = await iotClient.getDevice({name: devicePath});
// See full list of device fields: https://cloud.google.com/iot/docs/reference/cloudiot/rest/v1/projects.locations.registries.devices
// Warning! Use snake_case field names.
const fieldMask = {
paths: [
'id',
'name',
'num_id',
'credentials',
'last_heartbeat_time',
'last_event_time',
'last_state_time',
'last_config_ack_time',
'last_config_send_time',
'blocked',
'last_error_time',
'last_error_status',
'config',
'state',
'log_level',
'metadata',
'gateway_config',
],
};

const [response] = await iotClient.getDevice({
name: devicePath,
fieldMask,
});
const data = response;

console.log('Found device:', deviceId, data);
Expand Down

0 comments on commit a97ed10

Please sign in to comment.