1 //Create a class for relay switch device
3 import Timer.SimulatedTimer
5 public class RelaySwitches {
11 //If we have only one device
12 private String id = "relaySwitchID0"
13 private String label = "relaySwitch0"
14 private String displayName = "relaySwitch0"
15 private String switchState = "off"
16 private String currentSwitch = "off"
17 private String switchLatestValue = "off"
19 RelaySwitches(Closure sendEvent, int deviceNumbers) {
20 this.sendEvent = sendEvent
21 this.timers = new SimulatedTimer()
22 this.deviceNumbers = deviceNumbers
23 this.relaySwitches = []
25 relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue))
28 //Methods for closures
29 def count(Closure Input) {
30 relaySwitches.count(Input)
35 def each(Closure Input) {
36 relaySwitches.each(Input)
38 def find(Closure Input) {
39 relaySwitches.find(Input)
41 def collect(Closure Input) {
42 relaySwitches.collect(Input)
47 if (switchState != "on") {
49 switchLatestValue = switchState
55 def on(LinkedHashMap metaData) {
56 if (switchState != "on") {
57 def task = timers.runAfter(metaData["delay"]) {
59 switchLatestValue = switchState
67 if (switchState != "off") {
68 relaySwitches[0].off()
69 switchLatestValue = switchState
75 def off(LinkedHashMap metaData) {
76 if (switchState != "off") {
77 def task = timers.runAfter(metaData["delay"]) {
78 relaySwitches[0].off()
79 switchLatestValue = switchState
87 def setValue(LinkedHashMap eventDataMap) {
88 if (eventDataMap["value"] != relaySwitches[0].switchState) {
89 relaySwitches[0].setValue(eventDataMap["value"])
90 this.switchState = relaySwitches[0].switchState
91 this.switchLatestValue = relaySwitches[0].switchLatestValue
92 sendEvent(eventDataMap)
97 def currentValue(String deviceFeature) {
98 relaySwitches[0].currentValue(deviceFeature)
101 def latestValue(String deviceFeature) {
102 relaySwitches[0].latestValue(deviceFeature)