//Create a class for switch level package SwitchLevel import Timer.SimulatedTimer public class SwitchLevels { int deviceNumbers List switchLevels def timers def sendEvent //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" SwitchLevels(Closure sendEvent, int deviceNumbers) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.switchLevels = [] switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.switchState, this.switchLatestValue)) } //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() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { switchLatestValue = "off" switchState = "off" currentSwitch = "off" switchLevels[0].off() } } //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 getAt(int ix) { switchLevels[ix] } }