def sendEvent
//If we have only one device
- private int id = 40
- private String label = "switch"
- private String displayName = "switch"
+ private String id = "switchID0"
+ private String label = "switch0"
+ private String displayName = "switch0"
private String switchState = "off"
private String currentSwitch = "off"
private int currentLevel = 50
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))
- }
+
+ switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
}
//Methods for closures
def each(Closure Input) {
switches.each(Input)
}
+ def find(Closure Input) {
+ switches.find(Input)
+ }
+ def collect(Closure Input) {
+ switches.collect(Input)
+ }
//By Apps
def setLevel(int level) {
- switches*.setLevel(level)
+ switches[0].setLevel(level)
}
def on() {
- switches*.on()
+ switches[0].on()
}
def on(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- switches*.on()
+ switches[0].on()
}
}
def off() {
- switches*.off()
+ switches[0].off()
}
def off(LinkedHashMap metaData) {
def task = timers.runAfter(metaData["delay"]) {
- switches*.off()
+ switches[0].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
+ switches[0].setValue(eventDataMap["value"])
+ this.switchState = switches[0].switchState
+ this.switchLatestValue = switches[0].switchLatestValue
sendEvent(eventDataMap)
}
def currentValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].currentValue(deviceFeature)
- else
- switches*.currentValue(deviceFeature)
+ switches[0].currentValue(deviceFeature)
}
def latestValue(String deviceFeature) {
- if (deviceNumbers == 1)
- switches[0].latestValue(deviceFeature)
- else
- switches*.latestValue(deviceFeature)
+ switches[0].latestValue(deviceFeature)
}
def getAt(int ix) {