@@ -129,6 +129,10 @@ class Cayenne {
129
129
* Begin Device Attribute Routes
130
130
*/
131
131
132
+ /*
133
+ * Begin Device Attribute Routes
134
+ */
135
+
132
136
/**
133
137
* Gets all attribute groups and attributes for a device
134
138
* @param {String } deviceId The device id to get attributes for
@@ -142,27 +146,37 @@ class Cayenne {
142
146
}
143
147
144
148
/**
145
- * Create or Update an attribute group. Pass null to group_id to create a new group.
149
+ * Update an attribute group. Pass null to group_id to create a new group.
146
150
* @param {String } deviceId The id of the parent device
147
151
* @param {String? } groupId Optional: Updates group, if null creates instead
148
- * @param {Object } payload The group to create or update
152
+ * @param {Object } payload The group to update
149
153
* @param {UUID? } payload.id Optional: The group id, will be overriden by group_id parameter
150
154
* @param {String } payload.name The name of the group
151
155
* @param {Integer } payload.order The display order of the group
152
156
* @param {String? } payload.device_id Optional: The device id this group is attached to. Overriden by deviceId paramter
153
157
* @param {UUID } payload.user_id The user id of the device owner
154
158
* @param {UUID } payload.client_id The application id of the API call
155
159
*/
156
- createOrUpdateGroup ( deviceId , groupId , payload ) {
157
- var url = null ;
158
- if ( groupId == null ) {
159
- url = `${ this . url } /things/${ deviceId } /groups` ;
160
- } else {
161
- url = `${ this . url } /things/${ deviceId } /groups/${ groupId } ` ;
162
- }
160
+ updateGroup ( deviceId , groupId , payload ) {
161
+ const url = `${ this . url } /things/${ deviceId } /groups/${ groupId } ` ;
162
+
163
163
return this . auth . send ( this . service , 'PUT' , url , { payload } ) ;
164
164
}
165
165
166
+ /**
167
+ * Create an attribute group. Pass null to group_id to create a new group.
168
+ * @param {String } deviceId The id of the parent device
169
+ * @param {Object } payload The group to create
170
+ * @param {UUID? } payload.id Optional: The group id, will be overriden by group_id parameter
171
+ * @param {String } payload.name The name of the group
172
+ * @param {Integer } payload.order The display order of the group
173
+ */
174
+ createGroup ( deviceId , payload ) {
175
+ const url = `${ this . url } /things/${ deviceId } /groups` ;
176
+
177
+ return this . auth . send ( this . service , 'POST' , url , { payload } ) ;
178
+ }
179
+
166
180
/**
167
181
* Delete a group
168
182
* @param {String } deviceId
@@ -177,7 +191,6 @@ class Cayenne {
177
191
* Create or Update an attribute. Pass null to attribute_id to create a new attribute.
178
192
* @param {String } deviceId The id of the parent device
179
193
* @param {String } groupId The id of the parent group
180
- * @param {String? } attributeId Optional: Updates attribute, if null creates instead
181
194
* @param {Object } payload The attribute to create or update
182
195
* @param {UUID? } payload.id Optional: The attribute id, will be overriden by attributeId parameter
183
196
* @param {String } payload.name The name of the attribute
@@ -188,15 +201,32 @@ class Cayenne {
188
201
* @param {String } payload.value The value, contents vary based on value_type
189
202
* @param {String } payload.value_type The type of content contained in value string
190
203
*/
191
- createOrUpdateAttribute ( deviceId , groupId , attributeId , payload ) {
192
- var url = null ;
193
- if ( attributeId == null ) {
194
- url = `${ this . url } /things/${ deviceId } /groups/${ groupId } /attributes` ;
195
- } else {
196
- url = `${
197
- this . url
198
- } /things/${ deviceId } /groups/${ groupId } /attributes/${ attributeId } `;
199
- }
204
+ createAttribute ( deviceId , groupId , payload ) {
205
+ const url = `${ this . url } /things/${ deviceId } /groups/${ groupId } /attributes` ;
206
+
207
+ return this . auth . send ( this . service , 'POST' , url , { payload } ) ;
208
+ }
209
+
210
+ /**
211
+ * Update an attribute. Pass null to attribute_id to create a new attribute.
212
+ * @param {String } deviceId The id of the parent device
213
+ * @param {String } groupId The id of the parent group
214
+ * @param {String? } attributeId Updates attribute
215
+ * @param {Object } payload The attribute to update
216
+ * @param {UUID? } payload.id Optional: The attribute id, will be overriden by attributeId parameter
217
+ * @param {String } payload.name The name of the attribute
218
+ * @param {Integer } payload.order The display order of the attribute
219
+ * @param {String? } payload.device_id Optional: The device id this attribute is attached to. Overriden by deviceId paramter
220
+ * @param {UUID } payload.user_id The user id of the device owner
221
+ * @param {UUID? } payload.group_id The group id of the parent group
222
+ * @param {String } payload.value The value, contents vary based on value_type
223
+ * @param {String } payload.value_type The type of content contained in value string
224
+ */
225
+ updateAttribute ( deviceId , groupId , attributeId , payload ) {
226
+ const url = `${
227
+ this . url
228
+ } /things/${ deviceId } /groups/${ groupId } /attributes/${ attributeId } `;
229
+
200
230
return this . auth . send ( this . service , 'PUT' , url , { payload } ) ;
201
231
}
202
232
@@ -213,6 +243,19 @@ class Cayenne {
213
243
return this . auth . send ( this . service , 'DELETE' , url ) ;
214
244
}
215
245
246
+ /**
247
+ * Get an attribute
248
+ * @param {String } deviceId
249
+ * @param {String } groupId
250
+ * @param {String } attributeId
251
+ */
252
+ getAttribute ( deviceId , groupId , attributeId ) {
253
+ const url = `${
254
+ this . url
255
+ } /things/${ deviceId } /groups/${ groupId } /attributes/${ attributeId } `;
256
+ return this . auth . send ( this . service , 'GET' , url ) ;
257
+ }
258
+
216
259
/*
217
260
* End Device Attribute Routes
218
261
*/
@@ -295,6 +338,44 @@ class Cayenne {
295
338
return this . auth . send ( this . service , 'GET' , url ) ;
296
339
}
297
340
341
+ /**
342
+ * Gets V2 all things data types
343
+ * @param {Object } query
344
+ * @param {Number } [query.limit]
345
+ * @param {Number } [query.page]
346
+ */
347
+ getThingDataTypesV2 ( query ) {
348
+ const url = `${ this . url } /v2/things/datatypes` ;
349
+ return this . auth . send ( this . service , 'GET' , url , { query } ) ;
350
+ }
351
+
352
+ /**
353
+ * Get V2 one things data type
354
+ */
355
+ getThingDataTypeV2 ( id ) {
356
+ const url = `${ this . url } /v2/things/datatypes/${ id } ` ;
357
+ return this . auth . send ( this . service , 'GET' , url ) ;
358
+ }
359
+
360
+ /**
361
+ * Get V2 one things data type properties
362
+ * @param {Object } query
363
+ * @param {Number } [query.limit]
364
+ * @param {Number } [query.page]
365
+ */
366
+ getThingDataTypePropertiesV2 ( id , query ) {
367
+ const url = `${ this . url } /v2/things/datatypes/${ id } /properties` ;
368
+ return this . auth . send ( this . service , 'GET' , url , { query } ) ;
369
+ }
370
+
371
+ /**
372
+ * Get V2 one things data type property by it's id
373
+ */
374
+ getThingDataTypePropertyV2 ( id , pid ) {
375
+ const url = `${ this . url } /v2/things/datatypes/${ id } /properties/${ pid } ` ;
376
+ return this . auth . send ( this . service , 'GET' , url ) ;
377
+ }
378
+
298
379
/**
299
380
* Gets thing types by query
300
381
* @param {Object } query
0 commit comments