Removing getXXX methods + properties. Adding getProperty feature to SmartThing(s)
[smartthings-infrastructure.git] / StepSensor / StepSensors.groovy
index 021db256317e3006a4bf8b86ecbf2d3f8305604e..067481f4fcbaba1ffae72819291ad01384175f52 100644 (file)
@@ -1,79 +1,29 @@
 //Create a class for step sensor
 package StepSensor
-import Timer.SimulatedTimer
-
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class StepSensors {
-       private int deviceNumbers
-       private List stepSensors
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "stepSensorID0"
-       private String label = "stepSensor0"
-       private String displayName = "stepSensor0"
-       private int goal = 1000
-       private int steps = 0
+import SmartThing.SmartThings
 
+public class StepSensors extends SmartThings {
+       List stepSensors = new ArrayList()
                
-       StepSensors(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent              
-               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"].toInteger() != stepSensors[0].steps) {
-                               this.steps = eventDataMap["value"].toInteger()
-                               stepSensors[0].setValue(eventDataMap["value"], "steps")
-                               sendEvent(eventDataMap)
-                       }
-               } else if (eventDataMap["name"] == "goal") {
-                       if (eventDataMap["value"].toInteger() != stepSensors[0].goal) {
-                               this.goal = eventDataMap["value"].toInteger()
-                               stepSensors[0].setValue(eventDataMap["value"], "goal")
-                               sendEvent(eventDataMap)
-                       }
+       StepSensors(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               stepSensors = smartThings
+
+               // Initialization
+               String id = "stepSensorID0"
+               String label = "steps"
+               String displayName = "stepSensor"
+               Integer steps
+               Integer goal
+
+               if (init) {
+                       goal = 50
+                       steps = 35
+               } else {
+                       goal = 40
+                       steps = 60
                }
-       }
-
-       //Methods for closures
-       def count(Closure Input) {
-               stepSensors.count(Input)
-       }
-       def size() {
-               stepSensors.size()
-       }
-       def each(Closure Input) {
-               stepSensors.each(Input)
-       }
-       def find(Closure Input) {
-               stepSensors.find(Input)
-       }
-       def sort(Closure Input) {
-               stepSensors.sort(Input)
-       }
-       def collect(Closure Input) {
-               stepSensors.collect(Input)
-       }
-
-
-       def currentValue(String deviceFeature) {
-               stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
-       }
 
-       def getAt(int ix) {
-               stepSensors[ix]
+               stepSensors.add(new StepSensor(sendEvent, id, label, displayName, steps, goal))
        }
 }