//Create a class for switch device package Switch import Timer.SimulatedTimer public class Switches { int deviceNumbers List switches def timers def sendEvent //If we have only one device private int id = 40 private String label = "switch" private String displayName = "switch" private String switchState = "off" private String currentSwitch = "off" private int currentLevel = 50 private String switchLatestValue = "off" Switches(Closure sendEvent, int deviceNumbers) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.deviceNumbers = deviceNumbers this.switches = [] for (int i = 0;i < deviceNumbers;i++) { switches.add(new Switch(sendEvent, i+40, label+i.toString(), displayName+i.toString(), this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue)) } } //Methods for closures def count(Closure Input) { switches.count(Input) } def size() { switches.size() } def each(Closure Input) { switches.each(Input) } //By Apps def setLevel(int level) { switches*.setLevel(level) } def on() { switches*.on() } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { switches*.on() } } def off() { switches*.off() } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { switches*.off() } } //By Model Checker def setValue(LinkedHashMap eventDataMap) { switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"]) if (deviceNumbers == 1) this.switchState = switches[eventDataMap["deviceId"]].switchState this.switchLatestValue = switches[eventDataMap["deviceId"]].switchLatestValue sendEvent(eventDataMap) } def currentValue(String deviceFeature) { if (deviceNumbers == 1) switches[0].currentValue(deviceFeature) else switches*.currentValue(deviceFeature) } def latestValue(String deviceFeature) { if (deviceNumbers == 1) switches[0].latestValue(deviceFeature) else switches*.latestValue(deviceFeature) } def getAt(int ix) { switches[ix] } }