Flatten the structure of event while-loop.
[smartthings-infrastructure.git] / StepSensor / StepSensors.groovy
index 8f0f165f70bf24148786cc2b7cf48187b11242de..021db256317e3006a4bf8b86ecbf2d3f8305604e 100644 (file)
@@ -2,6 +2,9 @@
 package StepSensor
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class StepSensors {
        private int deviceNumbers
        private List stepSensors
@@ -20,21 +23,26 @@ public class StepSensors {
                this.deviceNumbers = deviceNumbers
                this.stepSensors = []
 
+               /*def initGoal = Verify.getIntFromList(1000, 2000, 3000)
+               this.goal = initGoal
+               def initSteps = Verify.getIntFromList(0, 1, 2)
+               this.steps = initSteps*/
+
                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 +61,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)
        }