//Create a class for switch device package Switch import Timer.SimulatedTimer public class Switches { private int id = 0 private String displayName private String switchState private String switchLatestValue def sendEvent def timers Switches(Closure sendEvent, int id, String displayName, String switchState, String switchLatestValue) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.id = id this.displayName = displayName this.switchState = switchState this.switchLatestValue = switchLatestValue } //By Apps def on() { println("the switch with id:$id is on!") this.switchLatestValue = this.switchState this.switchState = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } def on(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { println("the switch with id:$id is on!") this.switchLatestValue = this.switchState this.switchState = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } } def off() { println("the switch with id:$id is off!") this.switchLatestValue = this.switchState this.switchState = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } def off(LinkedHashMap metaData) { def task = timers.runAfter(metaData["delay"]) { println("the switch with id:$id is off!") this.switchLatestValue = this.switchState this.switchState = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: []]) } } //By Model Checker def setValue(String value) { println("the switch with id:$id is $value!") this.switchLatestValue = this.switchState this.switchState = value } def currentValue(String deviceFeature) { if (deviceFeature == "switch") { return switchState } } def latestValue(String deviceFeature) { if (deviceFeature == "switch") { return switchLatestValue } } }