Infrastruction modification
[smartthings-infrastructure.git] / StepSensor / StepSensor.groovy
index 6ec578fa7cad1ec1d66776e10788f46b6ff22478..7dcdb83f8d283d345257101d1263280a75fcdf09 100644 (file)
@@ -1,44 +1,42 @@
 //Create a class for step sensor
 package StepSensor
-import Timer.SimulatedTimer
+import SmartThing.SmartThing
 
-public class StepSensor {
-       private String id
-       private String label
-       private String displayName
-       private int goal
-       private int steps
+public class StepSensor extends SmartThing {
+       // id, label, and display name of the device
+       StringBuilder id = new StringBuilder()
+       StringBuilder label = new StringBuilder()
+       StringBuilder displayName = new StringBuilder()
+       // Features with numberical values
+       MutableInteger currentGoal = new MutableInteger()
+       MutableInteger currentSteps = new MutableInteger()
+       // Maps from features to values
+       HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
 
-       StepSensor(String id, String label, String displayName, int steps, int goal) {
+       StepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentSteps, MutableInteger currentGoal) {
+               deviceIntValuesMap = deviceIntValueSmartThing
+               idSmartThing = id
+               labelSmartThing = label
+               displayNameSmartThing = displayName
+               sendEventSmartThings = sendEvent
+
+               // Initialization
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.steps = steps
-               this.goal = goal
-       }
+               this.currentSteps = currentSteps
+               this.currentGoal = currentGoal
 
-       //By Model Checker
-       def setValue(String value, String name) {
-               if (name == "steps") {
-                       println("the number of steps is changed to $value!")
-                       this.steps = value.toInteger()
-               } else if (name == "goal") {
-                       println("the goal is changed to $value!")
-                       this.goal = value.toInteger()
-               }
+               deviceIntValuesMap.put("steps", currentSteps)
+               deviceIntValuesMap.put("goal", currentGoal)
        }
 
-       def currentValue(String deviceFeature) {
-               if (deviceFeature == "steps")
-                       return steps
-               else if (deviceFeature == "goal")
-                       return goal
+       // Methods to return values
+       def getCurrentSteps() {
+               return currentSteps.getValue()
        }
 
-       def latestValue(String deviceFeature) {
-               if (deviceFeature == "steps")
-                       return steps
-               else if (deviceFeature == "goal")
-                       return goal
+       def getCurrentGoal() {
+               return currentGoal.getValue()
        }
 }