Fixing a bug in the event presence.present: name has to be the same as value.
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
index 2eb775e253434122396de4f3d19ca3da336121b1..1e8e68e226263d79acfd2c68ff046cb166f91cae 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,6 +25,16 @@ 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))
        }
                
@@ -55,17 +68,21 @@ public class Alarms {
 
        //By Apps
        def both() {
-               alarms[0].both()
-               alarmLatestValue = alarm
-               alarm = "both"
-               currentAlarm = "both"
+               if (alarm != "both") {
+                       alarms[0].both()
+                       alarmLatestValue = alarm
+                       alarm = "both"
+                       currentAlarm = "both"
+               }
        }
 
        def off() {
-               alarms[0].off()
-               alarmLatestValue = alarm
-               alarm = "off"
-               currentAlarm = "off"
+               if (alarm != "off") {
+                       alarms[0].off()
+                       alarmLatestValue = alarm
+                       alarm = "off"
+                       currentAlarm = "off"
+               }
        }
 
        def on() {
@@ -73,17 +90,21 @@ public class Alarms {
        }
 
        def siren() {
-               alarms[0].siren()
-               alarmLatestValue = alarm
-               alarm = "siren"
-               currentAlarm = "siren"
+               if (alarm != "siren") {
+                       alarms[0].siren()
+                       alarmLatestValue = alarm
+                       alarm = "siren"
+                       currentAlarm = "siren"
+               }
        }
 
        def strobe() {
-               alarms[0].strobe()
-               alarmLatestValue = alarm
-               alarm = "strobe"
-               currentAlarm = "strobe"
+               if (alarm != "strobe") {
+                       alarms[0].strobe()
+                       alarmLatestValue = alarm
+                       alarm = "strobe"
+                       currentAlarm = "strobe"
+               }
        }
 
        def currentValue(String deviceFeature) {