X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=SwitchLevel%2FSwitchLevels.groovy;h=8e06b66bb2be89592ca51aa3a93f66adae179034;hb=d0b538d93e64c63d2673796db08570953b57f947;hp=591611a6e8394be165e964960d50e86805dfd3ac;hpb=de35dfa319418baf7ba4bc2eeb4dbfc0fd20230a;p=smartthings-infrastructure.git diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy index 591611a..8e06b66 100644 --- a/SwitchLevel/SwitchLevels.groovy +++ b/SwitchLevel/SwitchLevels.groovy @@ -1,119 +1,45 @@ //Create a class for switch level package SwitchLevel -import Timer.SimulatedTimer +import SmartThing.SmartThings -//JPF's Verify API -import gov.nasa.jpf.vm.Verify +public class SwitchLevels extends SmartThings { + List switchLevels = new ArrayList() -public class SwitchLevels { - int deviceNumbers - List switchLevels - def timers - def sendEvent + SwitchLevels(Closure sendEvent, boolean init) { + // Only initialize one time since we only have one device for each capability + switchLevels = smartThings - //If we have only one device - private String id = "switchLevelID0" - private String label = "switchLevel0" - private String displayName = "switchLevel0" - private int level = 50 - private int rate = 50 - private String switchState = "off" - private String currentSwitch = "off" - private String switchLatestValue = "off" + // Initialization + StringBuilder id = new StringBuilder("switchLevelID0") + StringBuilder label = new StringBuilder("switchLevel") + StringBuilder displayName = new StringBuilder("switchLevel0") + MutableInteger level = new MutableInteger() - SwitchLevels(Closure sendEvent, int deviceNumbers) { - this.sendEvent = sendEvent - this.timers = new SimulatedTimer() - this.deviceNumbers = deviceNumbers - this.switchLevels = [] + if (init) + level.setValue(50) + else + level.setValue(60) - /*def initLevel = Verify.getIntFromList(30, 50, 70) - this.level = initLevel - def init = Verify.getBoolean() - if (init) { - this.switchState = "off" - this.currentSwitch = "off" - this.switchLatestValue = "off" - } else { - this.switchState = "on" - this.currentSwitch = "on" - this.switchLatestValue = "on" - }*/ - switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.switchState, this.switchLatestValue)) + switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, level)) } - //Methods for closures - def count(Closure Input) { - switchLevels.count(Input) - } - def size() { - switchLevels.size() - } - def each(Closure Input) { - switchLevels.each(Input) - } - def find(Closure Input) { - switchLevels.find(Input) - } - def sort(Closure Input) { - switchLevels.sort(Input) - } - def collect(Closure Input) { - switchLevels.collect(Input) - } - - //By Apps - def setLevel(int level) { - if (this.level != level) { - switchLevels[0].setLevel(level) - this.level = level - this.rate = level - } - } - - def on() { - switchLatestValue = "on" - switchState = "on" - currentSwitch = "on" - switchLevels[0].on() - } - - def on(LinkedHashMap metaData) { - def task = timers.runAfter(metaData["delay"]) { - switchLatestValue = "on" - switchState = "on" - currentSwitch = "on" - switchLevels[0].on() - } - } - - def off() { - switchLatestValue = "off" - switchState = "off" - currentSwitch = "off" - switchLevels[0].off() + // Methods to set values + def setLevel(String newValue) { + setLevel(newValue.toInteger()) } - def off(LinkedHashMap metaData) { - def task = timers.runAfter(metaData["delay"]) { - switchLatestValue = "off" - switchState = "off" - currentSwitch = "off" - switchLevels[0].off() - } + def setLevel(long newValue) { + setLevel((int) newValue) } - //By Model Checker - def setValue(LinkedHashMap eventDataMap) { - if (eventDataMap["value"].toInteger() != switchLevels[0].level) { - this.level = eventDataMap["value"].toInteger() - this.rate = eventDataMap["value"].toInteger() - switchLevels[0].setValue(eventDataMap["value"]) - sendEvent(eventDataMap) - } + def setLevel(int newValue) { + switchLevels[0].setLevel(newValue) } - def getAt(int ix) { - switchLevels[ix] + // Methods to return values + def getCurrentLevel() { + List tmpValues = new ArrayList() + tmpValues.add(switchLevels[0].getCurrentLevel()) + return tmpValues } }