@@ -131,6 +131,10 @@ class Cayenne {
131
131
* Begin Device Attribute Routes
132
132
*/
133
133
134
+ /*
135
+ * Begin Device Attribute Routes
136
+ */
137
+
134
138
/**
135
139
* Gets all attribute groups and attributes for a device
136
140
* @param {String } deviceId The device id to get attributes for
@@ -144,27 +148,37 @@ class Cayenne {
144
148
}
145
149
146
150
/**
147
- * Create or Update an attribute group. Pass null to group_id to create a new group.
151
+ * Update an attribute group. Pass null to group_id to create a new group.
148
152
* @param {String } deviceId The id of the parent device
149
153
* @param {String? } groupId Optional: Updates group, if null creates instead
150
- * @param {Object } payload The group to create or update
154
+ * @param {Object } payload The group to update
151
155
* @param {UUID? } payload.id Optional: The group id, will be overriden by group_id parameter
152
156
* @param {String } payload.name The name of the group
153
157
* @param {Integer } payload.order The display order of the group
154
158
* @param {String? } payload.device_id Optional: The device id this group is attached to. Overriden by deviceId paramter
155
159
* @param {UUID } payload.user_id The user id of the device owner
156
160
* @param {UUID } payload.client_id The application id of the API call
157
161
*/
158
- createOrUpdateGroup ( deviceId , groupId , payload ) {
159
- var url = null ;
160
- if ( groupId == null ) {
161
- url = `${ this . url } /things/${ deviceId } /groups` ;
162
- } else {
163
- url = `${ this . url } /things/${ deviceId } /groups/${ groupId } ` ;
164
- }
162
+ updateGroup ( deviceId , groupId , payload ) {
163
+ const url = `${ this . url } /things/${ deviceId } /groups/${ groupId } ` ;
164
+
165
165
return this . auth . send ( this . service , 'PUT' , url , { payload } ) ;
166
166
}
167
167
168
+ /**
169
+ * Create an attribute group. Pass null to group_id to create a new group.
170
+ * @param {String } deviceId The id of the parent device
171
+ * @param {Object } payload The group to create
172
+ * @param {UUID? } payload.id Optional: The group id, will be overriden by group_id parameter
173
+ * @param {String } payload.name The name of the group
174
+ * @param {Integer } payload.order The display order of the group
175
+ */
176
+ createGroup ( deviceId , payload ) {
177
+ const url = `${ this . url } /things/${ deviceId } /groups` ;
178
+
179
+ return this . auth . send ( this . service , 'POST' , url , { payload } ) ;
180
+ }
181
+
168
182
/**
169
183
* Delete a group
170
184
* @param {String } deviceId
@@ -179,7 +193,6 @@ class Cayenne {
179
193
* Create or Update an attribute. Pass null to attribute_id to create a new attribute.
180
194
* @param {String } deviceId The id of the parent device
181
195
* @param {String } groupId The id of the parent group
182
- * @param {String? } attributeId Optional: Updates attribute, if null creates instead
183
196
* @param {Object } payload The attribute to create or update
184
197
* @param {UUID? } payload.id Optional: The attribute id, will be overriden by attributeId parameter
185
198
* @param {String } payload.name The name of the attribute
@@ -190,15 +203,32 @@ class Cayenne {
190
203
* @param {String } payload.value The value, contents vary based on value_type
191
204
* @param {String } payload.value_type The type of content contained in value string
192
205
*/
193
- createOrUpdateAttribute ( deviceId , groupId , attributeId , payload ) {
194
- var url = null ;
195
- if ( attributeId == null ) {
196
- url = `${ this . url } /things/${ deviceId } /groups/${ groupId } /attributes` ;
197
- } else {
198
- url = `${
206
+ createAttribute ( deviceId , groupId , payload ) {
207
+ const url = `${ this . url } /things/${ deviceId } /groups/${ groupId } /attributes` ;
208
+
209
+ return this . auth . send ( this . service , 'POST' , url , { payload } ) ;
210
+ }
211
+
212
+ /**
213
+ * Update an attribute. Pass null to attribute_id to create a new attribute.
214
+ * @param {String } deviceId The id of the parent device
215
+ * @param {String } groupId The id of the parent group
216
+ * @param {String? } attributeId Updates attribute
217
+ * @param {Object } payload The attribute to update
218
+ * @param {UUID? } payload.id Optional: The attribute id, will be overriden by attributeId parameter
219
+ * @param {String } payload.name The name of the attribute
220
+ * @param {Integer } payload.order The display order of the attribute
221
+ * @param {String? } payload.device_id Optional: The device id this attribute is attached to. Overriden by deviceId paramter
222
+ * @param {UUID } payload.user_id The user id of the device owner
223
+ * @param {UUID? } payload.group_id The group id of the parent group
224
+ * @param {String } payload.value The value, contents vary based on value_type
225
+ * @param {String } payload.value_type The type of content contained in value string
226
+ */
227
+ updateAttribute ( deviceId , groupId , attributeId , payload ) {
228
+ const url = `${
199
229
this . url
200
230
} /things/${ deviceId } /groups/${ groupId } /attributes/${ attributeId } `;
201
- }
231
+
202
232
return this . auth . send ( this . service , 'PUT' , url , { payload } ) ;
203
233
}
204
234
@@ -215,10 +245,24 @@ class Cayenne {
215
245
return this . auth . send ( this . service , 'DELETE' , url ) ;
216
246
}
217
247
248
+ /**
249
+ * Get an attribute
250
+ * @param {String } deviceId
251
+ * @param {String } groupId
252
+ * @param {String } attributeId
253
+ */
254
+ getAttribute ( deviceId , groupId , attributeId ) {
255
+ const url = `${
256
+ this . url
257
+ } /things/${ deviceId } /groups/${ groupId } /attributes/${ attributeId } `;
258
+ return this . auth . send ( this . service , 'GET' , url ) ;
259
+ }
260
+
218
261
/*
219
262
* End Device Attribute Routes
220
263
*/
221
264
265
+
222
266
/*
223
267
* Begin Registry Routes
224
268
*/
0 commit comments