X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Switch%2FSwitches.groovy;h=5a2754042f05a585db006b4cf0326bcc38e457af;hb=853fd00f8cfdf3365aac210ed5649415b8aab5d3;hp=8c57869b54aadf78c3271ebc78409fc401f18cdf;hpb=b5602bde1f6ac15ef1fa8b1d6eceb68708a51ad1;p=smartthings-infrastructure.git diff --git a/Switch/Switches.groovy b/Switch/Switches.groovy index 8c57869..5a27540 100644 --- a/Switch/Switches.groovy +++ b/Switch/Switches.groovy @@ -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) } }