From 0bf912591383122eea91e5abebf705006a91202a Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 11 Sep 2013 10:41:09 +0300 Subject: [PATCH] Implemented preset support for custom commands. --- presets.coffee | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/presets.coffee b/presets.coffee index 10b12e1..9a58de3 100644 --- a/presets.coffee +++ b/presets.coffee @@ -75,6 +75,9 @@ exports.assertPresets = (deviceId, presetsHash, callback) -> switch c.type when 'value', 'age' projection[c.name] = 1 + when 'custom_command_value', 'custom_command_age' + # TODO only get individual commands + projection['_customCommands'] = 1 when 'firmware' projection['InternetGatewayDevice.DeviceInfo.SoftwareVersion'] = 1 when 'add_tag', 'delete_tag' @@ -120,6 +123,23 @@ exports.assertPresets = (deviceId, presetsHash, callback) -> getParameterValues.push(c.name) else expiry = Math.min(expiry, c.age - timeDiff) + when 'custom_command_value' + [filename, commandName] = c.command.split(' ', 2) + command = common.getParamValueFromPath(device, "_customCommands.#{filename}") + continue if not command? or commandName not in command._commands + dst = common.matchType(command._value, c.value) + if command._value != dst + taskList.push({device : deviceId, name : 'customCommand', command : c.command}) + when 'custom_command_age' + [filename, commandName] = c.command.split(' ', 2) + command = common.getParamValueFromPath(device, "_customCommands.#{filename}") + continue if not command? or commandName not in command._commands + timeDiff = (now - command._timestamp) / 1000 + if (c.age - timeDiff < config.PRESETS_TIME_PADDING) + expiry = Math.min(expiry, c.age) + taskList.push({device : deviceId, name : 'customCommand', command : c.command}) + else + expiry = Math.min(expiry, c.age - timeDiff) when 'add_tag' add_tags.push(c.tag) if not device['_tags']? or c.tag not in device['_tags'] when 'delete_tag' @@ -200,6 +220,7 @@ getObjectHash = (object) -> hash += "#{k}=#{object[k]}" return hash + accumulateConfigurations = (presets, objects) -> maxWeights = {} configurations = {}