Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
index bc805e1266bafb1d1f402ec8c7638bab13345648..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,6 +62,9 @@ public class Alarms {
        def find(Closure Input) {
                alarms.find(Input)
        }
+       def sort(Closure Input) {
+               alarms.sort(Input)
+       }
        def collect(Closure Input) {
                alarms.collect(Input)
        }
@@ -69,19 +72,19 @@ public class Alarms {
        //By Apps
        def both() {
                if (alarm != "both") {
-                       alarms[0].both()
-                       alarmLatestValue = alarm
+                       alarmLatestValue = "both"
                        alarm = "both"
                        currentAlarm = "both"
+                       alarms[0].both()
                }
        }
 
        def off() {
                if (alarm != "off") {
-                       alarms[0].off()
-                       alarmLatestValue = alarm
+                       alarmLatestValue = "off"
                        alarm = "off"
                        currentAlarm = "off"
+                       alarms[0].off()
                }
        }
 
@@ -91,19 +94,19 @@ public class Alarms {
 
        def siren() {
                if (alarm != "siren") {
-                       alarms[0].siren()
-                       alarmLatestValue = alarm
+                       alarmLatestValue = "siren"
                        alarm = "siren"
                        currentAlarm = "siren"
+                       alarms[0].siren()
                }
        }
 
        def strobe() {
                if (alarm != "strobe") {
-                       alarms[0].strobe()
-                       alarmLatestValue = alarm
+                       alarmLatestValue = "strobe"
                        alarm = "strobe"
                        currentAlarm = "strobe"
+                       alarms[0].strobe()
                }
        }