1 //Create a class for switch device
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class Switches {
14 //If we have only one device
15 private String id = "switchID0"
16 private String label = "switch0"
17 private String displayName = "switch0"
18 private String switchState = "off"
19 private String currentSwitch = "off"
20 private int currentLevel = 50
21 private String switchLatestValue = "off"
23 Switches(Closure sendEvent, int deviceNumbers) {
24 this.sendEvent = sendEvent
25 this.timers = new SimulatedTimer()
26 this.deviceNumbers = deviceNumbers
29 def initLevel = Verify.getIntFromList(30, 50, 70)
30 this.currentLevel = initLevel
31 def init = Verify.getBoolean()
33 this.switchState = "off"
34 this.currentSwitch = "off"
35 this.switchLatestValue = "off"
37 this.switchState = "on"
38 this.currentSwitch = "on"
39 this.switchLatestValue = "on"
42 switches.add(new Switch(sendEvent, id, label, displayName, this.switchState, this.currentSwitch, this.currentLevel, this.switchLatestValue))
45 //Methods for closures
46 def count(Closure Input) {
52 def each(Closure Input) {
55 def find(Closure Input) {
58 def collect(Closure Input) {
59 switches.collect(Input)
63 def setLevel(int level) {
64 switches[0].setLevel(level)
70 switchLatestValue = switchState
75 def on(LinkedHashMap metaData) {
76 def task = timers.runAfter(metaData["delay"]) {
78 switchLatestValue = switchState
86 switchLatestValue = switchState
91 def off(LinkedHashMap metaData) {
92 def task = timers.runAfter(metaData["delay"]) {
94 switchLatestValue = switchState
101 def setValue(LinkedHashMap eventDataMap) {
102 if (eventDataMap["value"] != switches[0].switchState) {
103 switches[0].setValue(eventDataMap["value"])
104 this.switchState = switches[0].switchState
105 this.switchLatestValue = switches[0].switchLatestValue
106 sendEvent(eventDataMap)
111 def currentValue(String deviceFeature) {
112 switches[0].currentValue(deviceFeature)
115 def latestValue(String deviceFeature) {
116 switches[0].latestValue(deviceFeature)