edit
[smartthings-infrastructure.git] / Alarm / Alarm.groovy
index a78c3c2877978d3c9e302d906a3e94c1ff20e0e8..6a0a24f1718acb4315f9a0d3e596940bd17f2bed 100644 (file)
@@ -26,8 +26,8 @@ public class Alarm {
 
        //By model checker
        def setValue(String value) {
-               this.alarmLatestValue = alarm
                println("the alarm with id:$id is triggered to $value!")
+               this.alarmLatestValue = value
                this.alarm = value
                this.currentAlarm = value
        }
@@ -35,12 +35,14 @@ public class Alarm {
 
        //By Apps
        def both() {
-               println("the alarm with id:$id is changed to both!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "both"
-               this.currentAlarm = "both"
-               sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "both"]])
+               if (alarm != "both") {
+                       println("the alarm with id:$id is changed to both!")
+                       this.alarmLatestValue = "both"
+                       this.alarm = "both"
+                       this.currentAlarm = "both"
+                       sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def on() {
@@ -48,30 +50,36 @@ public class Alarm {
        }
 
        def off() {
-               println("the alarm with id:$id is changed to off!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "off"
-               this.currentAlarm = "off"
-               sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+               if (alarm != "off") {
+                       println("the alarm with id:$id is changed to off!")
+                       this.alarmLatestValue = "off"
+                       this.alarm = "off"
+                       this.currentAlarm = "off"
+                       sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def siren() {
-               println("the alarm with id:$id is changed to siren!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "siren"
-               this.currentAlarm = "siren"
-               sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "siren"]])
+               if (alarm != "siren") {
+                       println("the alarm with id:$id is changed to siren!")
+                       this.alarmLatestValue = "siren"
+                       this.alarm = "siren"
+                       this.currentAlarm = "siren"
+                       sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def strobe() {
-               println("the alarm with id:$id is changed to strobe!")
-               this.alarmLatestValue = this.alarm
-               this.alarm = "strobe"
-               this.currentAlarm = "strobe"
-               sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "strobe"]])
+               if (alarm != "strobe") {
+                       println("the alarm with id:$id is changed to strobe!")
+                       this.alarmLatestValue = "strobe"
+                       this.alarm = "strobe"
+                       this.currentAlarm = "strobe"
+                       sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def currentValue(String deviceFeature) {