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