1 //Create a class for switch level
3 import Timer.SimulatedTimer
6 import gov.nasa.jpf.vm.Verify
8 public class SwitchLevels {
14 //If we have only one device
15 private String id = "switchLevelID0"
16 private String label = "switchLevel0"
17 private String displayName = "switchLevel0"
18 private int level = 50
20 private String switchState = "off"
21 private String currentSwitch = "off"
22 private String switchLatestValue = "off"
24 SwitchLevels(Closure sendEvent, int deviceNumbers) {
25 this.sendEvent = sendEvent
26 this.timers = new SimulatedTimer()
27 this.deviceNumbers = deviceNumbers
28 this.switchLevels = []
30 /*def initLevel = Verify.getIntFromList(30, 50, 70)
31 this.level = initLevel
32 def init = Verify.getBoolean()
34 this.switchState = "off"
35 this.currentSwitch = "off"
36 this.switchLatestValue = "off"
38 this.switchState = "on"
39 this.currentSwitch = "on"
40 this.switchLatestValue = "on"
42 switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.switchState, this.switchLatestValue))
45 //Methods for closures
46 def count(Closure Input) {
47 switchLevels.count(Input)
52 def each(Closure Input) {
53 switchLevels.each(Input)
55 def find(Closure Input) {
56 switchLevels.find(Input)
58 def collect(Closure Input) {
59 switchLevels.collect(Input)
63 def setLevel(int level) {
64 if (this.level != level) {
65 switchLevels[0].setLevel(level)
73 switchLatestValue = switchState
78 def on(LinkedHashMap metaData) {
79 def task = timers.runAfter(metaData["delay"]) {
81 switchLatestValue = switchState
89 switchLatestValue = switchState
94 def off(LinkedHashMap metaData) {
95 def task = timers.runAfter(metaData["delay"]) {
97 switchLatestValue = switchState
104 def setValue(LinkedHashMap eventDataMap) {
105 if (eventDataMap["value"] != switchLevels[0].level) {
106 switchLevels[0].setValue(eventDataMap["value"])
107 this.level = switchLevels[0].level
108 this.rate = switchLevels[0].level
109 sendEvent(eventDataMap)