X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=AccelerationSensor%2FAccelerationSensors.groovy;h=c218c2f813d0a7b637337f7c00a90034f97ab841;hb=HEAD;hp=7df4347f47bea0915b29841bea4374132309c9d9;hpb=622fbb619774231a71cb2a1dfd6df36f8f6659c9;p=smartthings-infrastructure.git diff --git a/AccelerationSensor/AccelerationSensors.groovy b/AccelerationSensor/AccelerationSensors.groovy index 7df4347..c218c2f 100644 --- a/AccelerationSensor/AccelerationSensors.groovy +++ b/AccelerationSensor/AccelerationSensors.groovy @@ -1,91 +1,25 @@ //Create a class for acceleration sensor package AccelerationSensor -import Timer.SimulatedTimer +import SmartThing.SmartThings -//JPF's Verify API -import gov.nasa.jpf.vm.Verify - -public class AccelerationSensors { - private int deviceNumbers - private List accelerationSensors - def sendEvent - - //For one device(We cannot have obj.id)-> We should have obj[0].id - private String id = "accelerationSensorID0" - private String label = "accelerationSensor0" - private String displayName = "accelerationSensor0" - private String acceleration = "inactive" - private String currentAcceleration = "inactive" - private String accelerationLatestValue = "inactive" - - - - AccelerationSensors(Closure sendEvent, int deviceNumbers) { - this.sendEvent = sendEvent - this.deviceNumbers = deviceNumbers - this.accelerationSensors = [] - - /*def init = Verify.getBoolean() - if (init) { - this.acceleration = "inactive" - this.accelerationLatestValue = "inactive" - } else { - this.acceleration = "active" - this.accelerationLatestValue = "active" - }*/ - accelerationSensors.add(new AccelerationSensor(id, label, displayName, this.acceleration, this.accelerationLatestValue)) - } - - //By Model Checker - def setValue(LinkedHashMap eventDataMap) { - if (eventDataMap["value"] != accelerationSensors[0].acceleration) { - this.accelerationLatestValue = eventDataMap["value"] - this.acceleration = eventDataMap["value"] - this.currentAcceleration = eventDataMap["value"] - accelerationSensors[0].setValue(eventDataMap["value"]) - sendEvent(eventDataMap) - } - } - - //methods - def eventsSince(Date dateObj) { - return accelerationSensors[0].eventsSince() - } +public class AccelerationSensors extends SmartThings { + List accelerationSensors = new ArrayList() - def statesSince(String info, Date dateObj) { - return accelerationSensors[0].statesSince() - } - - //Methods for closures - def count(Closure Input) { - accelerationSensors.count(Input) - } - def size() { - accelerationSensors.size() - } - def each(Closure Input) { - accelerationSensors.each(Input) - } - def sort(Closure Input) { - accelerationSensors.each(Input) - } - def find(Closure Input) { - accelerationSensors.find(Input) - } - def collect(Closure Input) { - accelerationSensors.collect(Input) - } - - - def currentValue(String deviceFeature) { - accelerationSensors[0].currentValue(deviceFeature)//It is called if we have only one device - } - - def latestValue(String deviceFeature) { - accelerationSensors[0].latestValue(deviceFeature)//It is called if we have only one device - } - - def getAt(int ix) { - accelerationSensors[ix] + AccelerationSensors(Closure sendEvent, boolean init) { + accelerationSensors = smartThings + + // Initialize + String id = "accelerationID0" + String label = "acceleration" + String displayName = "accelerationSensor" + String acceleration + + // Initialization + if (init) + acceleration = "inactive" + else + acceleration = "active" + + accelerationSensors.add(new AccelerationSensor(sendEvent, id, label, displayName, acceleration)) } }