Fixing bug in Mobile Presence class
[smartthings-infrastructure.git] / Switch / Switches.groovy
index cf8c06804dd387318d1841c3cadad4d8a996daf1..4729adf4e59840c404be776750c746f2915035b2 100644 (file)
@@ -1,61 +1,34 @@
 //Create a class for switch device
 package Switch
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class Switches {
-       int deviceNumbers       
-       List switches
-       def timers
-       def sendEvent
+public class Switches extends SmartThings {
+       List switches = new ArrayList()
 
-       //If we have only one device
-       private String id = "switchID0"
-       private String label = "switch0"
-       private String displayName = "switch0"
-       private String switchState = "off"
-       private String currentSwitch = "off"
-       private int currentLevel = 50
-       private String switchLatestValue = "off"
+       Switches(Closure sendEvent, boolean init) {
+               switches = smartThings
 
-       Switches(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent
-               this.timers = new SimulatedTimer()
-               this.deviceNumbers = deviceNumbers
-               this.switches = []
+               // Initialization
+               String id = "switchID0"
+               String label = "switch"
+               String displayName = "switch"
+               String currentSwitch
 
-               switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               switches.count(Input)
-       }
-       def size() {
-               switches.size()
-       }
-       def each(Closure Input) {
-               switches.each(Input)
-       }
-       def find(Closure Input) {
-               switches.find(Input)
-       }
-       def collect(Closure Input) {
-               switches.collect(Input)
-       }
+               if (init)
+                       currentSwitch = "off"
+               else
+                       currentSwitch = "on"
 
-       //By Apps
-       def setLevel(int level) {
-               switches[0].setLevel(level)
+               switches.add(new Switch(sendEvent, id, label, displayName, currentSwitch))
        }
 
+       // Methods to set values
        def on() {
                switches[0].on()
        }
 
        def on(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       switches[0].on()
-               }
+               on()
        }
 
        def off() {
@@ -63,29 +36,6 @@ public class Switches {
        }
 
        def off(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
-                       switches[0].off()
-               }
-       }
-
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               switches[0].setValue(eventDataMap["value"])
-               this.switchState = switches[0].switchState
-               this.switchLatestValue = switches[0].switchLatestValue
-               sendEvent(eventDataMap)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               switches[0].currentValue(deviceFeature)
-       }
-
-       def latestValue(String deviceFeature) {
-               switches[0].latestValue(deviceFeature)
-       }
-
-       def getAt(int ix) {
-               switches[ix]
+               off()
        }
 }