Implemented preset support for custom commands.
This commit is contained in:
1 parent
bfd7d70648
commit
0bf9125913
1 file changed
+21
@@ -75,6 +75,9 @@ exports.assertPresets = (deviceId, presetsHash, callback) ->
|
|||||||
switch c.type
|
switch c.type
|
||||||
when 'value', 'age'
|
when 'value', 'age'
|
||||||
projection[c.name] = 1
|
projection[c.name] = 1
|
||||||
|
when 'custom_command_value', 'custom_command_age'
|
||||||
|
# TODO only get individual commands
|
||||||
|
projection['_customCommands'] = 1
|
||||||
when 'firmware'
|
when 'firmware'
|
||||||
projection['InternetGatewayDevice.DeviceInfo.SoftwareVersion'] = 1
|
projection['InternetGatewayDevice.DeviceInfo.SoftwareVersion'] = 1
|
||||||
when 'add_tag', 'delete_tag'
|
when 'add_tag', 'delete_tag'
|
||||||
@@ -120,6 +123,23 @@ exports.assertPresets = (deviceId, presetsHash, callback) ->
|
|||||||
getParameterValues.push(c.name)
|
getParameterValues.push(c.name)
|
||||||
else
|
else
|
||||||
expiry = Math.min(expiry, c.age - timeDiff)
|
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'
|
when 'add_tag'
|
||||||
add_tags.push(c.tag) if not device['_tags']? or c.tag not in device['_tags']
|
add_tags.push(c.tag) if not device['_tags']? or c.tag not in device['_tags']
|
||||||
when 'delete_tag'
|
when 'delete_tag'
|
||||||
@@ -200,6 +220,7 @@ getObjectHash = (object) ->
|
|||||||
hash += "#{k}=#{object[k]}"
|
hash += "#{k}=#{object[k]}"
|
||||||
return hash
|
return hash
|
||||||
|
|
||||||
|
|
||||||
accumulateConfigurations = (presets, objects) ->
|
accumulateConfigurations = (presets, objects) ->
|
||||||
maxWeights = {}
|
maxWeights = {}
|
||||||
configurations = {}
|
configurations = {}
|
||||||
|
|||||||
Reference in new issue
Block a user