359248d9734b584feddbc65002d28e5acbc6dc43
[smartthings-infrastructure.git] / Switch / switches.groovy
1 //Create a class for switch device
2 package Switch
3
4 public class switches {
5         private int id = 0
6         private String displayName
7         private String currentSwitch
8         private String switchLatestValue
9
10         switches(int id, String displayName, String currentSwitch, String switchLatestValue) {
11                 this.id = id
12                 this.displayName = displayName
13                 this.currentSwitch = currentSwitch
14                 this.switchLatestValue = switchLatestValue
15         }
16
17         def on() {
18                 println("the switch with id:$id is on!")
19                 this.switchLatestValue = this.currentSwitch
20                 this.currentSwitch = "on"
21         }
22
23         def on(LinkedHashMap LHM) {
24                 sleep(LHM["delay"])
25                 println("the switch with id:$id is on!")
26                 this.switchLatestValue = this.currentSwitch
27                 this.currentSwitch = "on"
28         }
29
30         def off() {
31                 println("the switch with id:$id is off!")
32                 this.switchLatestValue = this.currentSwitch
33                 this.currentSwitch = "off"
34         }
35
36         def off(LinkedHashMap LHM) {
37                 sleep(LHM["delay"])
38                 println("the switch with id:$id is off!")
39                 this.switchLatestValue = this.currentSwitch
40                 this.currentSwitch = "off"
41         }
42         
43         def currentValue(String S) {
44                 if (S == "switch") {
45                         return currentSwitch
46                 }
47         }
48
49         def latestValue(String S) {
50                 if (S == "switch") {
51                         return switchLatestValue
52                 }
53         }
54 }