X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=RelaySwitch%2FRelaySwitches.groovy;h=76420f37974338fdfa11f8592cdca6ab64fe8a50;hb=d0b538d93e64c63d2673796db08570953b57f947;hp=fb5977b69dbb704303182e410ccc3e1456c5689e;hpb=2932def9bb947d617975235763f7338360f0e5a4;p=smartthings-infrastructure.git diff --git a/RelaySwitch/RelaySwitches.groovy b/RelaySwitch/RelaySwitches.groovy index fb5977b..76420f3 100644 --- a/RelaySwitch/RelaySwitches.groovy +++ b/RelaySwitch/RelaySwitches.groovy @@ -1,120 +1,49 @@ //Create a class for relay switch device package RelaySwitch -import Timer.SimulatedTimer +import SmartThing.SmartThings -public class RelaySwitches { - int deviceNumbers - List relaySwitches - def timers - def sendEvent +public class RelaySwitches extends SmartThings { + List relaySwitches = new ArrayList() - //If we have only one device - private String id = "relaySwitchID0" - private String label = "relaySwitch0" - private String displayName = "relaySwitch0" - private String switchState = "off" - private String currentSwitch = "off" - private String switchLatestValue = "off" + RelaySwitches(Closure sendEvent, boolean init) { + // Only initialize one time since we only have one device for each capability + relaySwitches = smartThings - RelaySwitches(Closure sendEvent, int deviceNumbers, boolean init) { - this.sendEvent = sendEvent - this.timers = new SimulatedTimer() - this.deviceNumbers = deviceNumbers - this.relaySwitches = [] + // Initialization + StringBuilder id = new StringBuilder("relaySwitchID0") + StringBuilder label = new StringBuilder("relaySwitch") + StringBuilder displayName = new StringBuilder("relaySwitch0") + StringBuilder currentSwitch = new StringBuilder() - if (init) { - this.switchState = "off" - this.currentSwitch = "off" - this.switchLatestValue = "off" - } else { - this.switchState = "on" - this.currentSwitch = "on" - this.switchLatestValue = "on" - } - relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue)) - } + if (init) + currentSwitch.append("off") + else + currentSwitch.append("on") - //Methods for closures - def count(Closure Input) { - relaySwitches.count(Input) - } - def size() { - relaySwitches.size() - } - def each(Closure Input) { - relaySwitches.each(Input) - } - def find(Closure Input) { - relaySwitches.find(Input) - } - def sort(Closure Input) { - relaySwitches.sort(Input) - } - def collect(Closure Input) { - relaySwitches.collect(Input) + relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, currentSwitch)) } - //By Apps + // Methods to set values def on() { - if (switchState != "on") { - switchLatestValue = "on" - switchState = "on" - currentSwitch = "on" - relaySwitches[0].on() - } + relaySwitches[0].on() } def on(LinkedHashMap metaData) { - if (switchState != "on") { - def task = timers.runAfter(metaData["delay"]) { - switchLatestValue = "on" - switchState = "on" - currentSwitch = "on" - relaySwitches[0].on() - } - } + on() } def off() { - if (switchState != "off") { - switchLatestValue = "off" - switchState = "off" - currentSwitch = "off" - relaySwitches[0].off() - } + relaySwitches[0].off() } def off(LinkedHashMap metaData) { - if (switchState != "off") { - def task = timers.runAfter(metaData["delay"]) { - switchLatestValue = "off" - switchState = "off" - currentSwitch = "off" - relaySwitches[0].off() - } - } - } - - //By Model Checker - def setValue(LinkedHashMap eventDataMap) { - if (eventDataMap["value"] != relaySwitches[0].switchState) { - this.switchState = eventDataMap["value"] - this.switchLatestValue = eventDataMap["value"] - relaySwitches[0].setValue(eventDataMap["value"]) - sendEvent(eventDataMap) - } - } - - - def currentValue(String deviceFeature) { - relaySwitches[0].currentValue(deviceFeature) - } - - def latestValue(String deviceFeature) { - relaySwitches[0].latestValue(deviceFeature) + off() } - def getAt(int ix) { - relaySwitches[ix] + // Methods to return values + def getCurrentSwitch() { + List tmpValues = new ArrayList() + tmpValues.add(relaySwitches[0].getCurrentSwitch()) + return tmpValues } }