Don't delete InternetGatewayDevice tree when reinitializing device

This commit is contained in:
Zaid Abdulla committed 2013-07-22 20:32:32 +03:00
1 parent 8167c0c6e5
commit bcfd56d868
2 files changed
+18 -16

No files matched your search

+3 -5
View File
@@ -117,11 +117,9 @@ updateDevice = (currentRequest, actions, callback) ->
)
else if updates['_lastBootstrap']?
# reinitialize on bootstrap event (e.g. firmware upgrade)
db.devicesCollection.update({'_id' : currentRequest.deviceId}, {'$unset' : 'InternetGatewayDevice'}, {safe: true}, (err, count) ->
task = {device : currentRequest.deviceId, name : 'init', timestamp : config.INIT_TIMESTAMP}
apiFunctions.insertTasks(task, (err) ->
callback(err) if callback?
)
task = {device : currentRequest.deviceId, name : 'init', timestamp : config.INIT_TIMESTAMP}
apiFunctions.insertTasks(task, (err) ->
callback(err) if callback?
)
else
callback() if callback?
+15 -11
View File
@@ -108,21 +108,25 @@ this.getParameterNames = (task, methodResponse, callback) ->
deviceUpdates = {parameterNames : methodResponse.parameterList}
path = if common.endsWith(task.parameterPath, '.') then task.parameterPath.slice(0, -1) else task.parameterPath
projection = {}
projection[path] = 1
projection[path] = 1 if !!task.parameterPath
# delete nonexisting params
db.devicesCollection.findOne({_id : task.device}, projection, (err, device) ->
if device
root = device
rootPath = ''
ps = path.split('.')
for p in ps
if root[p]?
root = root[p]
rootPath += "#{p}."
else
root = null
break
if !!task.parameterPath
root = device
rootPath = ''
ps = path.split('.')
for p in ps
if root[p]?
root = root[p]
rootPath += "#{p}."
else
root = null
break
else
root = device['InternetGatewayDevice']
rootPath = 'InternetGatewayDevice.'
if root
deviceUpdates.deletedObjects = []