Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / RelaySwitch / RelaySwitches.groovy
index d9615e2f8a64110f92506ee0b6999f2517e06a7d..bf89c2368a8ad4c54a194d11b96b8a444f371b92 100644 (file)
 //Create a class for relay switch device
 package RelaySwitch
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
+public class RelaySwitches extends SmartThings {
+       List relaySwitches = new ArrayList()
 
-public class RelaySwitches {
-       int deviceNumbers       
-       List relaySwitches
-       def timers
-       def sendEvent
+       RelaySwitches(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               relaySwitches = smartThings
 
-       //If we have only one device
-       private String id = "relaySwitchID0"
-       private String label = "relaySwitch0"
-       private String displayName = "relaySwitch0"
-       private String switchState = "off"
-       private String currentSwitch = "off"
-       private String switchLatestValue = "off"
+               // Initialization
+               String id = "relaySwitchID0"
+               String label = "switch"
+               String displayName = "relaySwitch"
+               String currentSwitch
 
-       RelaySwitches(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.relaySwitches = []
-
-               /*def init = Verify.getBoolean()
-               if (init) {
-                       this.switchState = "off"
-                       this.currentSwitch = "off"
-                       this.switchLatestValue = "off"
-               } else {
-                       this.switchState = "on"
-                       this.currentSwitch = "on"
-                       this.switchLatestValue = "on"
-               }*/
-               relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue))
-       }
+               if (init)
+                       currentSwitch = "off"
+               else
+                       currentSwitch = "on"
 
-       //Methods for closures
-       def count(Closure Input) {
-               relaySwitches.count(Input)
-       }
-       def size() {
-               relaySwitches.size()
-       }
-       def each(Closure Input) {
-               relaySwitches.each(Input)
-       }
-       def find(Closure Input) {
-               relaySwitches.find(Input)
-       }
-       def collect(Closure Input) {
-               relaySwitches.collect(Input)
+               relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, currentSwitch))
        }
 
-       //By Apps
+       // Methods to set values
        def on() {
-               if (switchState != "on") {
-                       relaySwitches[0].on()
-                       switchLatestValue = switchState
-                       switchState = "on"
-                       currentSwitch = "on"
-               }
+               relaySwitches[0].on()
        }
 
        def on(LinkedHashMap metaData) {
-               if (switchState != "on") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               relaySwitches[0].on()
-                               switchLatestValue = switchState
-                               switchState = "on"
-                               currentSwitch = "on"
-                       }
-               }
+               on()
        }
 
        def off() {
-               if (switchState != "off") {
-                       relaySwitches[0].off()
-                       switchLatestValue = switchState
-                       switchState = "off"
-                       currentSwitch = "off"
-               }
+               relaySwitches[0].off()
        }
 
        def off(LinkedHashMap metaData) {
-               if (switchState != "off") {
-                       def task = timers.runAfter(metaData["delay"]) {
-                               relaySwitches[0].off()
-                               switchLatestValue = switchState
-                               switchState = "off"
-                               currentSwitch = "off"
-                       }
-               }
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != relaySwitches[0].switchState) {
-                       relaySwitches[0].setValue(eventDataMap["value"])
-                       this.switchState = relaySwitches[0].switchState
-                       this.switchLatestValue = relaySwitches[0].switchLatestValue
-                       sendEvent(eventDataMap)
-               }
-       }
-
-
-       def currentValue(String deviceFeature) {
-               relaySwitches[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               relaySwitches[0].latestValue(deviceFeature)
-       }
-
-       def getAt(int ix) {
-               relaySwitches[ix]
+               off()
        }
 }