From 13da4dc2dac2b6752eab86378f2537ed6237f358 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Sun, 18 Aug 2013 11:02:20 +0300 Subject: [PATCH] Fixed a couple of bugs in AddObject method. --- tasks.coffee | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tasks.coffee b/tasks.coffee index 34e06e3..8f7f1a5 100644 --- a/tasks.coffee +++ b/tasks.coffee @@ -118,12 +118,9 @@ this.getParameterNames = (task, methodResponse, callback) -> rootPath = '' ps = path.split('.') for p in ps - if root[p]? - root = root[p] - rootPath += "#{p}." - else - root = null - break + rootPath += "#{p}." + root = root[p] + break if not root? else root = device['InternetGatewayDevice'] rootPath = 'InternetGatewayDevice.' @@ -135,7 +132,9 @@ this.getParameterNames = (task, methodResponse, callback) -> parameters[p[0]] = 1 for p in methodResponse.parameterList findMissingParameters(root, parameters, rootPath, deviceUpdates.deletedObjects) else - deviceUpdates.deletedObjects = [rootPath.slice(0, -1)] + # avoid adding and deleting the same param + if rootPath isnt task.parameterPath + deviceUpdates.deletedObjects = [rootPath.slice(0, -1)] # some devices don't return the root object as described in the standard. add manually to update timestamp deviceUpdates.parameterNames.push([task.parameterPath]) if !!task.parameterPath @@ -241,14 +240,16 @@ this.addObject = (task, methodResponse, callback) -> when 'getParameterValues' this.getParameterValues(task.subtask, methodResponse, (err, status, cwmpResponse, deviceUpdates) => common.extend(allDeviceUpdates, deviceUpdates) - if deviceUpdates and deviceUpdates.parameterValues - for p1 in deviceUpdates.parameterValues - for p2 in task.parameterValues - if common.endsWith(p1[0], ".#{p2[0]}") - t = if p2[2] then p2[2] else p1[2] - v = common.matchType(p1[1], p2[1]) - # TODO only include if writable - task.appliedParameterValues.push([p1[0], v, t]) + # if values are given, compare with default values + if task.parameterValues? + if deviceUpdates and deviceUpdates.parameterValues? + for p1 in deviceUpdates.parameterValues + for p2 in task.parameterValues + if common.endsWith(p1[0], ".#{p2[0]}") + t = if p2[2] then p2[2] else p1[2] + v = common.matchType(p1[1], p2[1]) + # TODO only include if writable + task.appliedParameterValues.push([p1[0], v, t]) if methodResponse.faultcode? # Ignore GetParameterValues errors. A workaround for the crappy Seewon devices.