X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Switch%2FSwitches.groovy;h=152096db303471cfc66dfece1098095c9ea6e478;hb=591f965b054a99429e5f0c7c44078a58bcc38e06;hp=cf8c06804dd387318d1841c3cadad4d8a996daf1;hpb=2c464dd719752b34106af7eb1e7451e6e03072f6;p=smartthings-infrastructure.git diff --git a/Switch/Switches.groovy b/Switch/Switches.groovy index cf8c068..152096d 100644 --- a/Switch/Switches.groovy +++ b/Switch/Switches.groovy @@ -2,6 +2,10 @@ package Switch import Timer.SimulatedTimer +//JPF's Verify API +import gov.nasa.jpf.vm.Verify + + public class Switches { int deviceNumbers List switches @@ -17,12 +21,23 @@ public class Switches { private int currentLevel = 50 private String switchLatestValue = "off" - Switches(Closure sendEvent, int deviceNumbers) { + Switches(Closure sendEvent, int deviceNumbers, boolean init) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.switches = [] + if (init) { + this.switchState = "off" + this.currentSwitch = "off" + this.switchLatestValue = "off" + this.currentLevel = 50 + } else { + this.switchState = "on" + this.currentSwitch = "on" + this.switchLatestValue = "on" + this.currentLevel = 60 + } switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue)) } @@ -36,44 +51,69 @@ public class Switches { def each(Closure Input) { switches.each(Input) } + def eachWithIndex(Closure Input) { + switches.eachWithIndex(Input) + } def find(Closure Input) { switches.find(Input) } + def sort(Closure Input) { + switches.sort(Input) + } def collect(Closure Input) { switches.collect(Input) } //By Apps + def eventsSince(Date dateObj, LinkedHashMap metaData) { + return switches[0].eventsSince() + } + def setLevel(int level) { + currentLevel = level switches[0].setLevel(level) } def on() { + switchLatestValue = "on" + switchState = "on" + currentSwitch = "on" switches[0].on() } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { + switchLatestValue = "on" + switchState = "on" + currentSwitch = "on" switches[0].on() } } def off() { + switchLatestValue = "off" + switchState = "off" + currentSwitch = "off" switches[0].off() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { + switchLatestValue = "off" + switchState = "off" + currentSwitch = "off" switches[0].off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { - switches[0].setValue(eventDataMap["value"]) - this.switchState = switches[0].switchState - this.switchLatestValue = switches[0].switchLatestValue - sendEvent(eventDataMap) + if (eventDataMap["value"] != switches[0].switchState) { + this.switchState = eventDataMap["value"] + this.switchLatestValue = eventDataMap["value"] + switches[0].setValue(eventDataMap["value"]) + sendEvent(eventDataMap) + } }