1 //Create a class for switch device
4 public class switches {
6 private String displayName
7 private String currentSwitch
8 private String switchLatestValue
10 switches(int id, String displayName, String currentSwitch, String switchLatestValue) {
12 this.displayName = displayName
13 this.currentSwitch = currentSwitch
14 this.switchLatestValue = switchLatestValue
18 println("the switch with id:$id is on!")
19 this.switchLatestValue = this.currentSwitch
20 this.currentSwitch = "on"
23 def on(LinkedHashMap LHM) {
25 println("the switch with id:$id is on!")
26 this.switchLatestValue = this.currentSwitch
27 this.currentSwitch = "on"
31 println("the switch with id:$id is off!")
32 this.switchLatestValue = this.currentSwitch
33 this.currentSwitch = "off"
36 def off(LinkedHashMap LHM) {
38 println("the switch with id:$id is off!")
39 this.switchLatestValue = this.currentSwitch
40 this.currentSwitch = "off"
43 def currentValue(String S) {
49 def latestValue(String S) {
51 return switchLatestValue