Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
index 35c4ad9669d21dbeab9a5b4e8b5b2de7c7836c7f..daa025bb68fa78bcf92a648db386c0b4e31ac42c 100644 (file)
@@ -40,6 +40,9 @@ public class SwitchLevels {
        def find(Closure Input) {
                switchLevels.find(Input)
        }
+       def sort(Closure Input) {
+               switchLevels.sort(Input)
+       }
        def collect(Closure Input) {
                switchLevels.collect(Input)
        }
@@ -54,43 +57,43 @@ public class SwitchLevels {
        }
 
        def on() {
-               switchLevels[0].on()
-               switchLatestValue = switchState
+               switchLatestValue = "on"
                switchState = "on"
                currentSwitch = "on"
+               switchLevels[0].on()
        }
 
        def on(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
-                       switchLevels[0].on()
-                       switchLatestValue = switchState
+                       switchLatestValue = "on"
                        switchState = "on"
                        currentSwitch = "on"
+                       switchLevels[0].on()
                }
        }
 
        def off() {
-               switchLevels[0].off()
-               switchLatestValue = switchState
+               switchLatestValue = "off"
                switchState = "off"
                currentSwitch = "off"
+               switchLevels[0].off()
        }
 
        def off(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
-                       switchLevels[0].off()
-                       switchLatestValue = switchState
+                       switchLatestValue = "off"
                        switchState = "off"
                        currentSwitch = "off"
+                       switchLevels[0].off()
                }
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["value"] != switchLevels[0].level) {
+               if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
+                       this.level = eventDataMap["value"].toInteger()
+                       this.rate = eventDataMap["value"].toInteger()
                        switchLevels[0].setValue(eventDataMap["value"])
-                       this.level = switchLevels[0].level
-                       this.rate = switchLevels[0].level
                        sendEvent(eventDataMap)
                }
        }