Skip to content

Commit

Permalink
Merge pull request #253 from telefonicaid/bug/bothObjectIdAndIdStored
Browse files Browse the repository at this point in the history
FIX Both object_id and id stored for attributes
  • Loading branch information
XavierVal committed Jan 28, 2016
2 parents 86187a9 + f98b462 commit 5c2e909
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- ADD Timeinstant value with local time (#251)
- FIX Both object_id and id in attributes are stored, but only the id displayed (#250).
2 changes: 1 addition & 1 deletion lib/plugins/attributeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function extractSingleMapping(previous, current) {

previous.direct[current.object_id] = current.name;
previous.types[current.object_id] = current.type;
previous.inverse[current.name] = current.id;
previous.inverse[current.name] = current.object_id;
return previous;
}

Expand Down
10 changes: 6 additions & 4 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,14 @@ function registerDevice(deviceObj, callback) {
defaults = [null, null, [], [], [], []];

function setDefaultAttributeIds(attribute) {
if (!attribute.id && attribute.name) {
attribute.id = attribute.name;
/* jshint camelcase: false */

if (!attribute.object_id && attribute.name) {
attribute.object_id = attribute.name;
}

if (!attribute.name && attribute.id) {
attribute.name = attribute.id;
if (!attribute.name && attribute.object_id) {
attribute.name = attribute.object_id;
}

return attribute;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/northBound/deviceProvisioningServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function handleProvision(req, res, next) {
*/
function attributeToProvisioningAPIFormat(attribute) {
return {
object_id: attribute.id,
object_id: attribute.object_id,
name: attribute.name,
type: attribute.type
};
Expand Down
7 changes: 4 additions & 3 deletions test/unit/device-provisioning-api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,13 @@ describe('Device provisioning API: Provision devices', function() {
});

it('should store fill the device ID in case only the name is provided', function(done) {
/* jshint camelcase:false */
request(options, function(error, response, body) {
response.statusCode.should.equal(201);
iotAgentLib.listDevices('smartGondor', '/gardens', function(error, results) {
results.devices[0].lazy[0].id.should.equal('luminance');
results.devices[0].commands[0].id.should.equal('commandAttr');
results.devices[0].active[0].id.should.equal('attr_name');
results.devices[0].lazy[0].object_id.should.equal('luminance');
results.devices[0].commands[0].object_id.should.equal('commandAttr');
results.devices[0].active[0].object_id.should.equal('attr_name');
done();
});
});
Expand Down

0 comments on commit 5c2e909

Please sign in to comment.