1 //Create a class for relay switch device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class RelaySwitches {
14 //If we have only one device
15 private String id = "relaySwitchID0"
16 private String label = "relaySwitch0"
17 private String displayName = "relaySwitch0"
18 private String switchState = "off"
19 private String currentSwitch = "off"
20 private String switchLatestValue = "off"
22 RelaySwitches(Closure sendEvent, int deviceNumbers) {
23 this.sendEvent = sendEvent
24 this.timers = new SimulatedTimer()
25 this.deviceNumbers = deviceNumbers
26 this.relaySwitches = []
28 /*def init = Verify.getBoolean()
30 this.switchState = "off"
31 this.currentSwitch = "off"
32 this.switchLatestValue = "off"
34 this.switchState = "on"
35 this.currentSwitch = "on"
36 this.switchLatestValue = "on"
38 relaySwitches.add(new RelaySwitch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.switchLatestValue))
41 //Methods for closures
42 def count(Closure Input) {
43 relaySwitches.count(Input)
48 def each(Closure Input) {
49 relaySwitches.each(Input)
51 def find(Closure Input) {
52 relaySwitches.find(Input)
54 def sort(Closure Input) {
55 relaySwitches.sort(Input)
57 def collect(Closure Input) {
58 relaySwitches.collect(Input)
63 if (switchState != "on") {
64 switchLatestValue = "on"
71 def on(LinkedHashMap metaData) {
72 if (switchState != "on") {
73 def task = timers.runAfter(metaData["delay"]) {
74 switchLatestValue = "on"
83 if (switchState != "off") {
84 switchLatestValue = "off"
87 relaySwitches[0].off()
91 def off(LinkedHashMap metaData) {
92 if (switchState != "off") {
93 def task = timers.runAfter(metaData["delay"]) {
94 switchLatestValue = "off"
97 relaySwitches[0].off()
103 def setValue(LinkedHashMap eventDataMap) {
104 if (eventDataMap["value"] != relaySwitches[0].switchState) {
105 this.switchState = eventDataMap["value"]
106 this.switchLatestValue = eventDataMap["value"]
107 relaySwitches[0].setValue(eventDataMap["value"])
108 sendEvent(eventDataMap)
113 def currentValue(String deviceFeature) {
114 relaySwitches[0].currentValue(deviceFeature)
117 def latestValue(String deviceFeature) {
118 relaySwitches[0].latestValue(deviceFeature)