Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
index b2759bde5235e87bce5129cfa5264ecd0443916d..3e0842dcab40702150ddbff4c5f10dcbfb55fabb 100644 (file)
@@ -41,10 +41,10 @@ public class Alarms {
        //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)
                }
        }
@@ -62,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() {
@@ -86,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) {