1 //Create a class for step sensor
3 import Timer.SimulatedTimer
5 public class StepSensors {
6 private int deviceNumbers
7 private List stepSensors
10 //For one device(We cannot have obj.id)-> We should have obj[0].id
11 private String id = "stepSensorID0"
12 private String label = "stepSensor0"
13 private String displayName = "stepSensor0"
14 private int goal = 1000
18 StepSensors(Closure sendEvent, int deviceNumbers) {
19 this.sendEvent = sendEvent
20 this.deviceNumbers = deviceNumbers
23 stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
27 def setValue(LinkedHashMap eventDataMap) {
28 if (eventDataMap["name"] == "steps") {
29 if (eventDataMap["value"] != stepSensors[0].steps) {
30 stepSensors[0].setValue(eventDataMap["value"], "steps")
31 this.steps = stepSensors[0].steps
32 sendEvent(eventDataMap)
34 } else if (eventDataMap["value"] == "goal") {
35 if (eventDataMap["value"] != stepSensors[0].goal) {
36 stepSensors[0].setValue(eventDataMap["value"], "goal")
37 this.goal = stepSensors[0].goal
38 sendEvent(eventDataMap)
43 //Methods for closures
44 def count(Closure Input) {
45 stepSensors.count(Input)
50 def each(Closure Input) {
51 stepSensors.each(Input)
53 def find(Closure Input) {
54 stepSensors.find(Input)
56 def collect(Closure Input) {
57 stepSensors.collect(Input)
61 def currentValue(String deviceFeature) {
62 stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device