a71a49f0b355ca75cefa29d333d57cabf50197d6
[smartthings-infrastructure.git] / Switch / Switches.groovy
1 //Create a class for switch device
2 package Switch
3 import SmartThing.SmartThings
4
5 public class Switches extends SmartThings {
6         List switches = new ArrayList()
7
8         Switches(Closure sendEvent, boolean init) {
9                 switches = smartThings
10
11                 // Initialization
12                 StringBuilder id = new StringBuilder("switchID0")
13                 StringBuilder label = new StringBuilder("switch")
14                 StringBuilder displayName = new StringBuilder("switch0")
15                 StringBuilder currentSwitch = new StringBuilder()
16
17                 if (init)
18                         currentSwitch.append("off")
19                 else
20                         currentSwitch.append("on")
21
22                 switches.add(new Switch(sendEvent, id, label, displayName, currentSwitch))
23         }
24
25         // Methods to set values
26         def on() {
27                 switches[0].on()
28         }
29
30         def on(LinkedHashMap metaData) {
31                 on()
32         }
33
34         def off() {
35                 switches[0].off()
36         }
37
38         def off(LinkedHashMap metaData) {
39                 off()
40         }
41
42         // Methods to return values
43         def getCurrentSwitch() {
44                 List tmpValues = new ArrayList()
45                 tmpValues.add(switches[0].getCurrentSwitch())
46                 return tmpValues
47         }
48 }