Adding path explorations for initializations.
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
1 //Create a class for alarm device
2 package Alarm
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class Alarms {
9         int deviceNumbers       
10         List alarms
11         def timers
12         def sendEvent
13
14         //If we have only one device
15         private String id = "alarmID0"
16         private String label = "alarm0"
17         private String displayName = "alarm0"
18         private String alarm = "off"
19         private String currentAlarm = "off"
20         private String alarmLatestValue = "off"
21
22         Alarms(Closure sendEvent, int deviceNumbers) {
23                 this.sendEvent = sendEvent
24                 this.timers = new SimulatedTimer()
25                 this.deviceNumbers = deviceNumbers
26                 this.alarms = []
27
28                 def init = Verify.getBoolean()
29                 if (init) {
30                         this.alarm = "off"
31                         this.currentAlarm = "off"
32                         this.alarmLatestValue = "off"
33                 } else {
34                         this.alarm = "on"
35                         this.currentAlarm = "on"
36                         this.alarmLatestValue = "on"
37                 }
38                 alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
39         }
40                 
41         //By Model Checker
42         def setValue(LinkedHashMap eventDataMap) {
43                 if (eventDataMap["value"] != alarms[0].alarm) {
44                         alarms[0].setValue(eventDataMap["value"])
45                         this.alarmLatestValue = alarms[0].alarmLatestValue
46                         this.alarm = alarms[0].alarm
47                         this.currentAlarm = alarms[0].alarm
48                         sendEvent(eventDataMap)
49                 }
50         }
51
52         //Methods for closures
53         def count(Closure Input) {
54                 alarms.count(Input)
55         }
56         def size() {
57                 alarms.size()
58         }
59         def each(Closure Input) {
60                 alarms.each(Input)
61         }
62         def find(Closure Input) {
63                 alarms.find(Input)
64         }
65         def collect(Closure Input) {
66                 alarms.collect(Input)
67         }
68
69         //By Apps
70         def both() {
71                 alarms[0].both()
72                 alarmLatestValue = alarm
73                 alarm = "both"
74                 currentAlarm = "both"
75         }
76
77         def off() {
78                 alarms[0].off()
79                 alarmLatestValue = alarm
80                 alarm = "off"
81                 currentAlarm = "off"
82         }
83
84         def on() {
85                 both()
86         }
87
88         def siren() {
89                 alarms[0].siren()
90                 alarmLatestValue = alarm
91                 alarm = "siren"
92                 currentAlarm = "siren"
93         }
94
95         def strobe() {
96                 alarms[0].strobe()
97                 alarmLatestValue = alarm
98                 alarm = "strobe"
99                 currentAlarm = "strobe"
100         }
101
102         def currentValue(String deviceFeature) {
103                 alarms[0].currentValue(deviceFeature)
104         }
105
106         def latestValue(String deviceFeature) {
107                 alarms[0].latestValue(deviceFeature)
108         }
109
110         def getAt(int ix) {
111                 alarms[ix]
112         }
113 }