//Create a class for switch device package Switch public class switches { private int id = 0 private String displayName private String currentSwitch private String switchLatestValue switches(int id, String displayName, String currentSwitch, String switchLatestValue) { this.id = id this.displayName = displayName this.currentSwitch = currentSwitch this.switchLatestValue = switchLatestValue } def on() { println("the switch with id:$id is on!") this.switchLatestValue = this.currentSwitch this.currentSwitch = "on" } def on(LinkedHashMap LHM) { sleep(LHM["delay"]) println("the switch with id:$id is on!") this.switchLatestValue = this.currentSwitch this.currentSwitch = "on" } def off() { println("the switch with id:$id is off!") this.switchLatestValue = this.currentSwitch this.currentSwitch = "off" } def off(LinkedHashMap LHM) { sleep(LHM["delay"]) println("the switch with id:$id is off!") this.switchLatestValue = this.currentSwitch this.currentSwitch = "off" } def currentValue(String S) { if (S == "switch") { return currentSwitch } } def latestValue(String S) { if (S == "switch") { return switchLatestValue } } }