"First commit!"
[smartthings-infrastructure.git] / Switch / switching.groovy
diff --git a/Switch/switching.groovy b/Switch/switching.groovy
new file mode 100644 (file)
index 0000000..da2f30c
--- /dev/null
@@ -0,0 +1,74 @@
+//Create a class for switch device
+package Switch
+
+public class switching{
+       List switches
+       int count
+
+       switching(int count) {
+               this.count = count
+               if (count == 1) {
+                       switches = [new switches(0, "switch0", "off", "off")]
+               } else if (count == 2) {
+                       switches = [new switches(0, "switch0", "off", "off"),new switches(1, "switch1", "off", "off")]
+               } else if (count == 3) {
+                       switches = [new switches(0, "switch0", "off", "off"),new switches(1, "switch1", "off", "off"),new switches(2, "switch2", "off", "off")]
+               }
+       }
+
+       def on() {
+               if (count == 1) {
+                       switches[0].on()
+               } else {
+                       switches*.on()
+               }
+       }
+
+       def on(LinkedHashMap LHM) {
+               if (count == 1) {
+                       sleep(LHM["delay"])
+                       switches[0].on()
+               } else {
+                       sleep(LHM["delay"])
+                       switches*.on()
+               }
+       }
+
+       def off() {
+               if (count == 1) {
+                       switches[0].off()       
+               } else {
+                       switches*.off()
+               }
+       }
+
+       def off(LinkedHashMap LHM) {
+               if (count == 1) {
+                       sleep(LHM["delay"])
+                       switches[0].off()
+               } else {
+                       sleep(LHM["delay"])
+                       switches*.off()
+               }
+       }
+
+       def currentValue(String S) {
+               if (count == 1) {
+                       switches[0].currentValue(S)
+               } else {
+                       switches*.currentValue(S)
+               }
+       }
+
+       def latestValue(String S) {
+               if (count == 1) {
+                       switches[0].latestValue(S)
+               } else {
+                       switches*.latestValue(S)
+               }
+       }
+
+       def getAt(int ix) {
+               switches[ix]
+       }
+}