Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / Alarm / Alarm.groovy
index d3834f1d799a9f613f046380fdd6d3475d2c7b5c..446face170f690887418132786420ff969a678f0 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
        }
@@ -37,11 +37,13 @@ public class Alarm {
        def both() {
                if (alarm != "both") {
                        println("the alarm with id:$id is changed to both!")
-                       this.alarmLatestValue = this.alarm
+                       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"}'])
+                       sendEvent([name: "alarm.both", value: "both", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -52,33 +54,39 @@ public class Alarm {
        def off() {
                if (alarm != "off") {
                        println("the alarm with id:$id is changed to off!")
-                       this.alarmLatestValue = this.alarm
+                       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"}'])
+                       sendEvent([name: "alarm.off", value: "off", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
        def siren() {
                if (alarm != "siren") {
                        println("the alarm with id:$id is changed to siren!")
-                       this.alarmLatestValue = this.alarm
+                       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"}'])
+                       sendEvent([name: "alarm.siren", value: "siren", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
        def strobe() {
                if (alarm != "strobe") {
                        println("the alarm with id:$id is changed to strobe!")
-                       this.alarmLatestValue = this.alarm
+                       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"}'])
+                       sendEvent([name: "alarm.strobe", value: "strobe", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }