Skip to content

Commit b7a7673

Browse files
author
Alvaro Vega Garcia
committed
Merge pull request #246 from telefonicaid/bug/objectIdInsteadOfIdInDefaultIDs
FIX Object IDs in get provisioned device
2 parents f9e7fff + f680b2f commit b7a7673

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Getting the information of a provisioned device returns an spurious 'id' attribute in attribute descriptions (#245).

lib/services/northBound/deviceProvisioningServer.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ function handleProvision(req, res, next) {
116116
async.map(extractDevices(), provisionSingleDevice, handleProvisioningFinish);
117117
}
118118

119+
/**
120+
* Translate an attribute from the internal representaiton format to the one required by the Provisioning API.
121+
*
122+
* @param {Object} attribute Attribute in internal representation format.
123+
* @return {{object_id: *, name: *, type: *}} Attribute in Device Provisioning API format.
124+
*/
125+
function attributeToProvisioningAPIFormat(attribute) {
126+
return {
127+
object_id: attribute.id,
128+
name: attribute.name,
129+
type: attribute.type
130+
};
131+
}
132+
119133
/**
120134
* Translate between the inner model format to the external Device Provisioning API one.
121135
*
@@ -131,8 +145,8 @@ function toProvisioningAPIFormat(device) {
131145
entity_name: device.name,
132146
entity_type: device.type,
133147
timezone: device.timezone,
134-
attributes: device.active,
135-
lazy: device.lazy,
148+
attributes: device.active.map(attributeToProvisioningAPIFormat),
149+
lazy: device.lazy.map(attributeToProvisioningAPIFormat),
136150
static_attributes: device.staticAttributes,
137151
internal_attributes: device.internalAttributes,
138152
protocol: device.protocol

test/unit/listProvisionedDevices-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ describe('Device provisioning API: List provisioned devices', function() {
184184
done();
185185
});
186186
});
187+
188+
it('should return the appropriate attribute fields', function(done) {
189+
request(options, function(error, response, body) {
190+
/* jshint camelcase:false */
191+
192+
var parsedBody;
193+
194+
should.not.exist(error);
195+
196+
parsedBody = JSON.parse(body);
197+
should.exist(parsedBody.attributes[0].object_id);
198+
parsedBody.attributes[0].object_id.should.equal('attr_name');
199+
parsedBody.attributes[0].name.should.equal('attr_name');
200+
parsedBody.attributes[0].type.should.equal('string');
201+
done();
202+
});
203+
});
187204
});
188205
describe('When a request for an unexistent device arrives', function() {
189206
var options = {

0 commit comments

Comments
 (0)