"First commit!"
[smartthings-infrastructure.git] / Switch / switching.groovy
1 //Create a class for switch device
2 package Switch
3
4 public class switching{
5         List switches
6         int count
7
8         switching(int count) {
9                 this.count = count
10                 if (count == 1) {
11                         switches = [new switches(0, "switch0", "off", "off")]
12                 } else if (count == 2) {
13                         switches = [new switches(0, "switch0", "off", "off"),new switches(1, "switch1", "off", "off")]
14                 } else if (count == 3) {
15                         switches = [new switches(0, "switch0", "off", "off"),new switches(1, "switch1", "off", "off"),new switches(2, "switch2", "off", "off")]
16                 }
17         }
18
19         def on() {
20                 if (count == 1) {
21                         switches[0].on()
22                 } else {
23                         switches*.on()
24                 }
25         }
26
27         def on(LinkedHashMap LHM) {
28                 if (count == 1) {
29                         sleep(LHM["delay"])
30                         switches[0].on()
31                 } else {
32                         sleep(LHM["delay"])
33                         switches*.on()
34                 }
35         }
36
37         def off() {
38                 if (count == 1) {
39                         switches[0].off()       
40                 } else {
41                         switches*.off()
42                 }
43         }
44
45         def off(LinkedHashMap LHM) {
46                 if (count == 1) {
47                         sleep(LHM["delay"])
48                         switches[0].off()
49                 } else {
50                         sleep(LHM["delay"])
51                         switches*.off()
52                 }
53         }
54
55         def currentValue(String S) {
56                 if (count == 1) {
57                         switches[0].currentValue(S)
58                 } else {
59                         switches*.currentValue(S)
60                 }
61         }
62
63         def latestValue(String S) {
64                 if (count == 1) {
65                         switches[0].latestValue(S)
66                 } else {
67                         switches*.latestValue(S)
68                 }
69         }
70
71         def getAt(int ix) {
72                 switches[ix]
73         }
74 }