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

fix: add fieldMask for getDevice and listDevices #436

Merged
merged 4 commits into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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