From ee4747cbcaea987fc5e9f1c6636c27fa9dff0e3b Mon Sep 17 00:00:00 2001 From: Will Price Date: Fri, 29 Apr 2016 22:29:51 -0500 Subject: [PATCH] Modifying 'Simple Control' --- .../simple-control.src/simple-control.groovy | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/smartapps/roomieremote-roomieconnect/simple-control.src/simple-control.groovy b/smartapps/roomieremote-roomieconnect/simple-control.src/simple-control.groovy index 2fd4613..a0844fd 100644 --- a/smartapps/roomieremote-roomieconnect/simple-control.src/simple-control.groovy +++ b/smartapps/roomieremote-roomieconnect/simple-control.src/simple-control.groovy @@ -106,11 +106,31 @@ def handleDevicesWithIDs() for (devId in ids) { def device = allDevices.find { it.id == devId } - if (device) { - if (arguments) { - device."$command"(*arguments) - } else { - device."$command"() + // Check if we have a device that responds to the specified command + if (device && device.hasCommand(command)) { + switch (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 } else { @@ -176,11 +196,31 @@ def updateDevice() render status: 400, data: '{"msg": "command is required"}' } else { def device = allDevices.find { it.id == params.id } - if (device) { - if (arguments) { - device."$command"(*arguments) - } else { - device."$command"() + // Check if we have a device that responds to the specified command + if (device && device.hasCommand(command)) { + switch (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: "{}" } else {