Infrastructure that works for all the locks' group!
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy
new file mode 100644 (file)
index 0000000..9e6e8a9
--- /dev/null
@@ -0,0 +1,66 @@
+//Create a class for switch level
+package SwitchLevel
+import Timer.SimulatedTimer
+
+public class SwitchLevels {
+       int deviceNumbers       
+       List switchLevels
+       def timers
+       def sendEvent
+
+       //If we have only one device
+       private String id = "switchLevelID0"
+       private String label = "switchLevel0"
+       private String displayName = "switchLevel0"
+       private int level = 50
+       private int rate = 50
+
+       SwitchLevels(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent
+               this.timers = new SimulatedTimer()
+               this.deviceNumbers = deviceNumbers
+               this.switchLevels = []
+
+               switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level))
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               switchLevels.count(Input)
+       }
+       def size() {
+               switchLevels.size()
+       }
+       def each(Closure Input) {
+               switchLevels.each(Input)
+       }
+       def find(Closure Input) {
+               switchLevels.find(Input)
+       }
+       def collect(Closure Input) {
+               switchLevels.collect(Input)
+       }
+
+       //By Apps
+       def setLevel(int level) {
+               if (this.level != level) {
+                       switchLevels[0].setLevel(level)
+                       this.level = level
+                       this.rate = level
+               }
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != switchLevels[0].level) {
+                       switchLevels[0].setValue(eventDataMap["value"])
+                       this.level = switchLevels[0].level
+                       this.rate = switchLevels[0].level
+                       sendEvent(eventDataMap)
+               }
+       }
+
+       def getAt(int ix) {
+               switchLevels[ix]
+       }
+}