//Create a class for step sensor
package StepSensor
-import Timer.SimulatedTimer
-
-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, boolean init) {
- this.sendEvent = sendEvent
- this.deviceNumbers = deviceNumbers
- this.stepSensors = []
+ StepSensors(Closure sendEvent, boolean init) {
+ // Only initialize one time since we only have one device for each capability
+ stepSensors = smartThings
+
+ // Initialization
+ StringBuilder id = new StringBuilder("stepSensorID0")
+ StringBuilder label = new StringBuilder("stepSensor")
+ StringBuilder displayName = new StringBuilder("stepSensor0")
+ MutableInteger steps = new MutableInteger()
+ MutableInteger goal = new MutableInteger()
if (init) {
- this.goal = 50
- this.steps = 35
+ goal.setValue(50)
+ steps.setValue(35)
} else {
- this.goal = 40
- this.steps = 60
- }
- 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)
- }
+ goal.setValue(40)
+ steps.setValue(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
+ stepSensors.add(new StepSensor(sendEvent, id, label, displayName, steps, goal))
}
- def latestValue(String deviceFeature) {
- stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
+ // Methods to return values
+ def getCurrentSteps() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(stepSensors[0].getCurrentSteps())
+ return tmpValues
}
- def getAt(int ix) {
- stepSensors[ix]
+ def getCurrentGoal() {
+ List tmpValues = new ArrayList()
+ tmpValues.add(stepSensors[0].getCurrentGoal())
+ return tmpValues
}
}