X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Switch%2FSwitches.groovy;h=a13030a7d71a216344c9edb2fa50677d4189c5fd;hb=6918d9fc27dcd56ee0e1a77702238b8f2b470b82;hp=8c57869b54aadf78c3271ebc78409fc401f18cdf;hpb=b5602bde1f6ac15ef1fa8b1d6eceb68708a51ad1;p=smartthings-infrastructure.git diff --git a/Switch/Switches.groovy b/Switch/Switches.groovy index 8c57869..a13030a 100644 --- a/Switch/Switches.groovy +++ b/Switch/Switches.groovy @@ -26,10 +26,10 @@ public class Switches { this.deviceNumbers = deviceNumbers this.switches = [] - /*def initLevel = Verify.getIntFromList(30, 50, 70) + def initLevel = Verify.getIntFromList(30, 50, 70) this.currentLevel = initLevel def init = Verify.getBoolean() - if (init) { + /*if (init) { this.switchState = "off" this.currentSwitch = "off" this.switchLatestValue = "off" @@ -55,54 +55,57 @@ public class Switches { def find(Closure Input) { switches.find(Input) } + def sort(Closure Input) { + switches.sort(Input) + } def collect(Closure Input) { switches.collect(Input) } //By Apps def setLevel(int level) { - switches[0].setLevel(level) currentLevel = level + switches[0].setLevel(level) } def on() { - switches[0].on() - switchLatestValue = switchState + switchLatestValue = "on" switchState = "on" currentSwitch = "on" + switches[0].on() } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switches[0].on() - switchLatestValue = switchState + switchLatestValue = "on" switchState = "on" currentSwitch = "on" + switches[0].on() } } def off() { - switches[0].off() - switchLatestValue = switchState + switchLatestValue = "off" switchState = "off" currentSwitch = "off" + switches[0].off() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { - switches[0].off() - switchLatestValue = switchState + switchLatestValue = "off" switchState = "off" currentSwitch = "off" + switches[0].off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { if (eventDataMap["value"] != switches[0].switchState) { + this.switchState = eventDataMap["value"] + this.switchLatestValue = eventDataMap["value"] switches[0].setValue(eventDataMap["value"]) - this.switchState = switches[0].switchState - this.switchLatestValue = switches[0].switchLatestValue sendEvent(eventDataMap) } }