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, boolean init) {
19 this.sendEvent = sendEvent
20 this.deviceNumbers = deviceNumbers
30 stepSensors.add(new StepSensor(id, label, displayName, this.steps, this.goal))
34 def setValue(LinkedHashMap eventDataMap) {
35 if (eventDataMap["name"] == "steps") {
36 if (eventDataMap["value"].toInteger() != stepSensors[0].steps) {
37 this.steps = eventDataMap["value"].toInteger()
38 stepSensors[0].setValue(eventDataMap["value"], "steps")
39 sendEvent(eventDataMap)
41 } else if (eventDataMap["name"] == "goal") {
42 if (eventDataMap["value"].toInteger() != stepSensors[0].goal) {
43 this.goal = eventDataMap["value"].toInteger()
44 stepSensors[0].setValue(eventDataMap["value"], "goal")
45 sendEvent(eventDataMap)
50 //Methods for closures
51 def count(Closure Input) {
52 stepSensors.count(Input)
57 def each(Closure Input) {
58 stepSensors.each(Input)
60 def find(Closure Input) {
61 stepSensors.find(Input)
63 def sort(Closure Input) {
64 stepSensors.sort(Input)
66 def collect(Closure Input) {
67 stepSensors.collect(Input)
71 def currentValue(String deviceFeature) {
72 stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device
75 def latestValue(String deviceFeature) {
76 stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device