X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=StepSensor%2FStepSensors.groovy;h=d9200c6a24e258144af1c4ca66576836e6a407d6;hp=8f0f165f70bf24148786cc2b7cf48187b11242de;hb=752df0b3baa7349d6a0f5bdefb7d644a552bea2e;hpb=d00fd74ad7e497d6849c284c6ba69db2d3ec8e65 diff --git a/StepSensor/StepSensors.groovy b/StepSensor/StepSensors.groovy index 8f0f165..d9200c6 100644 --- a/StepSensor/StepSensors.groovy +++ b/StepSensor/StepSensors.groovy @@ -15,26 +15,33 @@ public class StepSensors { private int steps = 0 - StepSensors(Closure sendEvent, int deviceNumbers) { + StepSensors(Closure sendEvent, int deviceNumbers, boolean init) { this.sendEvent = sendEvent this.deviceNumbers = deviceNumbers this.stepSensors = [] + if (init) { + this.goal = 50 + this.steps = 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"] != stepSensors[0].steps) { + if (eventDataMap["value"].toInteger() != stepSensors[0].steps) { + this.steps = eventDataMap["value"].toInteger() stepSensors[0].setValue(eventDataMap["value"], "steps") - this.steps = stepSensors[0].steps sendEvent(eventDataMap) } - } else if (eventDataMap["value"] == "goal") { - if (eventDataMap["value"] != stepSensors[0].goal) { + } else if (eventDataMap["name"] == "goal") { + if (eventDataMap["value"].toInteger() != stepSensors[0].goal) { + this.goal = eventDataMap["value"].toInteger() stepSensors[0].setValue(eventDataMap["value"], "goal") - this.goal = stepSensors[0].goal sendEvent(eventDataMap) } } @@ -53,6 +60,9 @@ public class StepSensors { def find(Closure Input) { stepSensors.find(Input) } + def sort(Closure Input) { + stepSensors.sort(Input) + } def collect(Closure Input) { stepSensors.collect(Input) } @@ -62,6 +72,10 @@ public class StepSensors { stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device } + def latestValue(String deviceFeature) { + stepSensors[0].currentValue(deviceFeature)//It is called if we have only one device + } + def getAt(int ix) { stepSensors[ix] }