//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()
}
}