Modifying 'Simple Control'

This commit is contained in:
Will Price
2016-04-29 22:29:51 -05:00
parent 0d2c0faa4f
commit ee4747cbca

View File

@@ -106,11 +106,31 @@ def handleDevicesWithIDs()
for (devId in ids) for (devId in ids)
{ {
def device = allDevices.find { it.id == devId } def device = allDevices.find { it.id == devId }
if (device) { // Check if we have a device that responds to the specified command
if (arguments) { if (device && device.hasCommand(command)) {
device."$command"(*arguments) switch (command)
} else { {
device."$command"() case "on":
device.on()
break
case "off":
device.off()
break
case "setLevel":
device.setLevel(*arguments)
break
case "playText":
device.playText(*arguments)
break
case "lock":
device.lock()
break
case "unlock":
device.unlock()
break
default:
httpError(400, "Command ${command} cannot be sent to the target device")
break
} }
success = true success = true
} else { } else {
@@ -176,11 +196,31 @@ def updateDevice()
render status: 400, data: '{"msg": "command is required"}' render status: 400, data: '{"msg": "command is required"}'
} else { } else {
def device = allDevices.find { it.id == params.id } def device = allDevices.find { it.id == params.id }
if (device) { // Check if we have a device that responds to the specified command
if (arguments) { if (device && device.hasCommand(command)) {
device."$command"(*arguments) switch (command)
} else { {
device."$command"() case "on":
device.on()
break
case "off":
device.off()
break
case "setLevel":
device.setLevel(*arguments)
break
case "playText":
device.playText(*arguments)
break
case "lock":
device.lock()
break
case "unlock":
device.unlock()
break
default:
httpError(400, "Command ${command} cannot be sent to the target device")
break
} }
render status: 204, data: "{}" render status: 204, data: "{}"
} else { } else {