Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
index 2eb775e253434122396de4f3d19ca3da336121b1..3e0842dcab40702150ddbff4c5f10dcbfb55fabb 100644 (file)
@@ -2,6 +2,9 @@
 package Alarm
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class Alarms {
        int deviceNumbers       
        List alarms
@@ -22,16 +25,26 @@ public class Alarms {
                this.deviceNumbers = deviceNumbers
                this.alarms = []
 
+               def init = Verify.getBoolean()
+               if (init) {
+                       this.alarm = "off"
+                       this.currentAlarm = "off"
+                       this.alarmLatestValue = "off"
+               } else {
+                       this.alarm = "on"
+                       this.currentAlarm = "on"
+                       this.alarmLatestValue = "on"
+               }
                alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
        }
                
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != alarms[0].alarm) {
+                       this.alarmLatestValue = eventDataMap["value"]
+                       this.alarm = eventDataMap["value"]
+                       this.currentAlarm = eventDataMap["value"]
                        alarms[0].setValue(eventDataMap["value"])
-                       this.alarmLatestValue = alarms[0].alarmLatestValue
-                       this.alarm = alarms[0].alarm
-                       this.currentAlarm = alarms[0].alarm
                        sendEvent(eventDataMap)
                }
        }
@@ -49,23 +62,30 @@ public class Alarms {
        def find(Closure Input) {
                alarms.find(Input)
        }
+       def sort(Closure Input) {
+               alarms.sort(Input)
+       }
        def collect(Closure Input) {
                alarms.collect(Input)
        }
 
        //By Apps
        def both() {
-               alarms[0].both()
-               alarmLatestValue = alarm
-               alarm = "both"
-               currentAlarm = "both"
+               if (alarm != "both") {
+                       alarmLatestValue = "both"
+                       alarm = "both"
+                       currentAlarm = "both"
+                       alarms[0].both()
+               }
        }
 
        def off() {
-               alarms[0].off()
-               alarmLatestValue = alarm
-               alarm = "off"
-               currentAlarm = "off"
+               if (alarm != "off") {
+                       alarmLatestValue = "off"
+                       alarm = "off"
+                       currentAlarm = "off"
+                       alarms[0].off()
+               }
        }
 
        def on() {
@@ -73,17 +93,21 @@ public class Alarms {
        }
 
        def siren() {
-               alarms[0].siren()
-               alarmLatestValue = alarm
-               alarm = "siren"
-               currentAlarm = "siren"
+               if (alarm != "siren") {
+                       alarmLatestValue = "siren"
+                       alarm = "siren"
+                       currentAlarm = "siren"
+                       alarms[0].siren()
+               }
        }
 
        def strobe() {
-               alarms[0].strobe()
-               alarmLatestValue = alarm
-               alarm = "strobe"
-               currentAlarm = "strobe"
+               if (alarm != "strobe") {
+                       alarmLatestValue = "strobe"
+                       alarm = "strobe"
+                       currentAlarm = "strobe"
+                       alarms[0].strobe()
+               }
        }
 
        def currentValue(String deviceFeature) {