Skip to content

Commit

Permalink
Merge pull request #406 from telefonicaid/task/fixRetrieveDevice
Browse files Browse the repository at this point in the history
Task/fix retrieve device
  • Loading branch information
XavierVal authored Jun 27, 2016
2 parents c7b8cb2 + 00f387d commit 9b0cdea
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 195 deletions.
7 changes: 2 additions & 5 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
- ADD migration tool to migrate data from C++ IoTAgents to Node.js based ones (#388)
- FIX changing the log level with environment variables did not work
- Add functions to allow the IoTAs to check or create devices (#392)
- ADD version retrieval path (#395)
- Use the attributes defined in the Configuration as default alias values (#397)
- Merge configuration information in the retrieveDevice() function (#405)
- Expose the singleConfigurationMode attribute using environment variables (#404)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ The following table shows the accepted environment variables, as well as the con
| IOTA_MONGO_HOST | mongodb.host |
| IOTA_MONGO_PORT | mongodb.port |
| IOTA_MONGO_DB | mongodb.db |
| IOTA_SINGLE_MODE | singleConfigurationMode |

## <a name="aboutapi"/> About API
The library provides a simple operation to retrieve information about the library and the IoTA using it. A GET request
Expand Down
4 changes: 4 additions & 0 deletions lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ function processEnvironmentVariables() {
if (process.env.IOTA_MONGO_REPLICASET) {
config.mongodb.replicaSet = process.env.IOTA_MONGO_REPLICASET;
}

if (process.env.IOTA_SINGLE_MODE) {
config.singleConfigurationMode = process.env.IOTA_SINGLE_MODE;
}
}

function setConfig(newConfig) {
Expand Down
18 changes: 15 additions & 3 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ function checkRegistry(fn) {
function findOrCreate(deviceId, group, callback) {
getDevice(deviceId, group.service, group.subservice, function(error, device) {
if (!error && device) {
callback(null, device);
callback(null, device, group);
} else if (error.name === 'DEVICE_NOT_FOUND') {
var newDevice = {
id: deviceId,
Expand All @@ -631,7 +631,9 @@ function findOrCreate(deviceId, group, callback) {
newDevice.protocol = config.getConfig().iotManager.protocol;
}

registerDevice(newDevice, callback);
registerDevice(newDevice, function(error, device) {
callback(error, device, group);
});
} else {
callback(error);
}
Expand Down Expand Up @@ -662,7 +664,17 @@ function retrieveDevice(deviceId, apiKey, callback) {
} else {
async.waterfall([
apply(groupService.get, config.getConfig().defaultResource || '', apiKey),
apply(findOrCreate, deviceId)
apply(findOrCreate, deviceId),
apply(mergeDeviceWithConfiguration,
[
'lazy',
'active',
'staticAttributes',
'commands',
'subscriptions'
],
[null, null, [], [], [], [], []]
)
], callback);
}
}
Expand Down
Loading

0 comments on commit 9b0cdea

Please sign in to comment.