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 sort(Closure Input) {
42 relaySwitches.sort(Input)
44 def collect(Closure Input) {
45 relaySwitches.collect(Input)
50 if (switchState != "on") {
51 switchLatestValue = "on"
58 def on(LinkedHashMap metaData) {
59 if (switchState != "on") {
60 def task = timers.runAfter(metaData["delay"]) {
61 switchLatestValue = "on"
70 if (switchState != "off") {
71 switchLatestValue = "off"
74 relaySwitches[0].off()
78 def off(LinkedHashMap metaData) {
79 if (switchState != "off") {
80 def task = timers.runAfter(metaData["delay"]) {
81 switchLatestValue = "off"
84 relaySwitches[0].off()
90 def setValue(LinkedHashMap eventDataMap) {
91 if (eventDataMap["value"] != relaySwitches[0].switchState) {
92 this.switchState = eventDataMap["value"]
93 this.switchLatestValue = eventDataMap["value"]
94 relaySwitches[0].setValue(eventDataMap["value"])
95 sendEvent(eventDataMap)
100 def currentValue(String deviceFeature) {
101 relaySwitches[0].currentValue(deviceFeature)
104 def latestValue(String deviceFeature) {
105 relaySwitches[0].latestValue(deviceFeature)