1 //Create a class for switch device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
9 public class Switches {
15 //If we have only one device
16 private String id = "switchID0"
17 private String label = "switch0"
18 private String displayName = "switch0"
19 private String switchState = "off"
20 private String currentSwitch = "off"
21 private int currentLevel = 50
22 private String switchLatestValue = "off"
24 Switches(Closure sendEvent, int deviceNumbers, boolean init) {
25 this.sendEvent = sendEvent
26 this.timers = new SimulatedTimer()
27 this.deviceNumbers = deviceNumbers
31 this.switchState = "off"
32 this.currentSwitch = "off"
33 this.switchLatestValue = "off"
34 this.currentLevel = 50
36 this.switchState = "on"
37 this.currentSwitch = "on"
38 this.switchLatestValue = "on"
39 this.currentLevel = 60
41 switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
44 //Methods for closures
45 def count(Closure Input) {
51 def each(Closure Input) {
54 def eachWithIndex(Closure Input) {
55 switches.eachWithIndex(Input)
57 def find(Closure Input) {
60 def sort(Closure Input) {
63 def collect(Closure Input) {
64 switches.collect(Input)
68 def eventsSince(Date dateObj, LinkedHashMap metaData) {
69 return switches[0].eventsSince()
72 def setLevel(int level) {
74 switches[0].setLevel(level)
78 switchLatestValue = "on"
84 def on(LinkedHashMap metaData) {
85 def task = timers.runAfter(metaData["delay"]) {
86 switchLatestValue = "on"
94 switchLatestValue = "off"
100 def off(LinkedHashMap metaData) {
101 def task = timers.runAfter(metaData["delay"]) {
102 switchLatestValue = "off"
104 currentSwitch = "off"
110 def setValue(LinkedHashMap eventDataMap) {
111 if (eventDataMap["value"] != switches[0].switchState) {
112 this.switchState = eventDataMap["value"]
113 this.switchLatestValue = eventDataMap["value"]
114 switches[0].setValue(eventDataMap["value"])
115 sendEvent(eventDataMap)
120 def currentValue(String deviceFeature) {
121 switches[0].currentValue(deviceFeature)
124 def latestValue(String deviceFeature) {
125 switches[0].latestValue(deviceFeature)