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