1 //Create a class for switch device
4 public class Switching{
10 Switching(Closure sendEvent, int deviceNumbers) {
11 this.sendEvent = sendEvent
12 this.timers = new Timer()
13 this.deviceNumbers = deviceNumbers
16 for (int i = 0;i < deviceNumbers;i++) {
17 switches.add(new Switches(sendEvent, id, "switch"+id.toString(), "off", "off"))
27 def on(LinkedHashMap metaData) {
28 def task = timers.runAfter(metaData["delay"]) {
37 def off(LinkedHashMap metaData) {
38 def task = timers.runAfter(metaData["delay"]) {
44 def setValue(LinkedHashMap eventDataMap) {
45 switches[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
46 sendEvent(eventDataMap)
50 def currentValue(String deviceFeature) {
51 if (deviceNumbers == 1)
52 switches[0].currentValue(deviceFeature)
54 switches*.currentValue(deviceFeature)
57 def latestValue(String deviceFeature) {
58 if (deviceNumbers == 1)
59 switches[0].latestValue(deviceFeature)
61 switches*.latestValue(deviceFeature)