Adding missing methods etc.
[smartthings-infrastructure.git] / StepSensor / StepSensors.groovy
index 8f0f165f70bf24148786cc2b7cf48187b11242de..d9200c6a24e258144af1c4ca66576836e6a407d6 100644 (file)
@@ -15,26 +15,33 @@ public class StepSensors {
        private int steps = 0
 
                
-       StepSensors(Closure sendEvent, int deviceNumbers) {
+       StepSensors(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent              
                this.deviceNumbers = deviceNumbers
                this.stepSensors = []
 
+               if (init) {
+                       this.goal = 50
+                       this.steps = 35
+               } else {
+                       this.goal = 40
+                       this.steps = 60
+               }
                stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["name"] == "steps") {
-                       if (eventDataMap["value"] != stepSensors[0].steps) {
+                       if (eventDataMap["value"].toInteger() != stepSensors[0].steps) {
+                               this.steps = eventDataMap["value"].toInteger()
                                stepSensors[0].setValue(eventDataMap["value"], "steps")
-                               this.steps = stepSensors[0].steps
                                sendEvent(eventDataMap)
                        }
-               } else if (eventDataMap["value"] == "goal") {
-                       if (eventDataMap["value"] != stepSensors[0].goal) {
+               } else if (eventDataMap["name"] == "goal") {
+                       if (eventDataMap["value"].toInteger() != stepSensors[0].goal) {
+                               this.goal = eventDataMap["value"].toInteger()
                                stepSensors[0].setValue(eventDataMap["value"], "goal")
-                               this.goal = stepSensors[0].goal
                                sendEvent(eventDataMap)
                        }
                }
@@ -53,6 +60,9 @@ public class StepSensors {
        def find(Closure Input) {
                stepSensors.find(Input)
        }
+       def sort(Closure Input) {
+               stepSensors.sort(Input)
+       }
        def collect(Closure Input) {
                stepSensors.collect(Input)
        }
@@ -62,6 +72,10 @@ public class StepSensors {
                stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
        }
 
+       def latestValue(String deviceFeature) {
+               stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+       }
+
        def getAt(int ix) {
                stepSensors[ix]
        }