Infrastruction modification
[smartthings-infrastructure.git] / SleepSensor / SleepSensors.groovy
index 0db103302ed0869fbc2c8170ec124d9b34645f4a..7f8eb12a2dbeef0b73edfbc9c4006b6cb61716a1 100644 (file)
@@ -1,62 +1,32 @@
 //Create a class for sleep sensor
 package SleepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-public class SleepSensors {
-       private int deviceNumbers
-       private List sleepSensors
-       def sendEvent
+public class SleepSensors extends SmartThings {
+       List sleepSensors = new ArrayList()
+       
+       SleepSensors(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               sleepSensors = smartThings
 
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "sleepSensorID0"
-       private String label = "sleepSensor0"
-       private String displayName = "sleepSensor0"
-       private String sleeping = "sleeping"
+               // Initialization
+               StringBuilder id = new StringBuilder("sleepSensorID0")
+               StringBuilder label = new StringBuilder("sleepSensor")
+               StringBuilder displayName = new StringBuilder("sleepSensor0")
+               StringBuilder sleeping = new StringBuilder()
 
-               
-       SleepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
-               this.sendEvent = sendEvent              
-               this.deviceNumbers = deviceNumbers
-               this.sleepSensors = []
+               if (init)
+                       sleeping.append("sleeping")
+               else
+                       sleeping.append("not sleeping")
 
-               if (init) {
-                       this.sleeping = "sleeping"
-               } else {
-                       this.sleeping = "not sleeping"
-               }
-               sleepSensors.add(new SleepSensor(id, label, displayName, this.sleeping))
+               sleepSensors.add(new SleepSensor(sendEvent, id, label, displayName, sleeping))
        }
 
-       //By Model Checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != sleepSensors[0].sleeping) {
-                       this.sleeping = eventDataMap["value"]
-                       sleepSensors[0].setValue(eventDataMap["value"])
-                       sendEvent(eventDataMap)
-               }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               sleepSensors.count(Input)
-       }
-       def size() {
-               sleepSensors.size()
-       }
-       def each(Closure Input) {
-               sleepSensors.each(Input)
-       }
-       def find(Closure Input) {
-               sleepSensors.find(Input)
-       }
-       def sort(Closure Input) {
-               sleepSensors.sort(Input)
-       }
-       def collect(Closure Input) {
-               sleepSensors.collect(Input)
-       }
-
-       def getAt(int ix) {
-               sleepSensors[ix]
+       // Methods to return values
+       def getCurrentSleeping() {
+               List tmpValues = new ArrayList()
+               tmpValues.add(sleepSensors[0].getCurrentSleeping())
+               return tmpValues
        }
 }