A minor change in classes
[smartthings-infrastructure.git] / StepSensor / StepSensor.groovy
1 //Create a class for step sensor
2 package StepSensor
3 import SmartThing.SmartThing
4
5 //Importing mutable integer class
6 import MutableInteger.MutableInteger
7
8 public class StepSensor extends SmartThing {
9         // id, label, and display name of the device
10         StringBuilder id = new StringBuilder()
11         StringBuilder label = new StringBuilder()
12         StringBuilder displayName = new StringBuilder()
13         // Features with numberical values
14         MutableInteger currentGoal = new MutableInteger()
15         MutableInteger currentSteps = new MutableInteger()
16         // Maps from features to values
17         HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
18
19         StepSensor(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentSteps, MutableInteger currentGoal) {
20                 deviceIntValuesMap = deviceIntValueSmartThing
21                 idSmartThing = id
22                 labelSmartThing = label
23                 displayNameSmartThing = displayName
24                 sendEventSmartThings = sendEvent
25
26                 // Initialization
27                 this.id = id
28                 this.label = label
29                 this.displayName = displayName
30                 this.currentSteps = currentSteps
31                 this.currentGoal = currentGoal
32
33                 deviceIntValuesMap.put("steps", currentSteps)
34                 deviceIntValuesMap.put("goal", currentGoal)
35         }
36
37         // Methods to return values
38         def getCurrentSteps() {
39                 return currentSteps.getValue()
40         }
41
42         def getCurrentGoal() {
43                 return currentGoal.getValue()
44         }
45 }