Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / Valve / Valve.groovy
index 4aaf5b3067f465602595f112dbdf56b8a2921895..75efd8a4d2c58b6434ee76f9e5db6ac53e74a753 100644 (file)
@@ -26,10 +26,12 @@ public class Valve {
        def open() {
                if (valve != "open") {
                        println("the valve with id:$id is open!")
-                       this.valveLatestValue = this.valve
+                       this.valveLatestValue = "open"
                        this.valve = "open"
                        sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -37,10 +39,12 @@ public class Valve {
                if (valve != "open") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the valve with id:$id is open!")
-                               this.valveLatestValue = this.valve
+                               this.valveLatestValue = "open"
                                this.valve = "open"
                                sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
                                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                               sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
+                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }
@@ -48,10 +52,12 @@ public class Valve {
        def close() {
                if (valve != "closed") {
                        println("the valve with id:$id is closed!")
-                       this.valveLatestValue = this.valve
+                       this.valveLatestValue = "closed"
                        this.valve = "closed"
                        sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
+                                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -59,10 +65,12 @@ public class Valve {
                if (valve != "closed") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the valve with id:$id is closed!")
-                               this.valveLatestValue = this.valve
+                               this.valveLatestValue = "closed"
                                this.valve = "closed"
                                sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
                                            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                               sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
+                                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }
@@ -70,7 +78,7 @@ public class Valve {
        //By Model Checker
        def setValue(String value) {
                println("the valve with id:$id is $value!")
-               this.valveLatestValue = this.valve
+               this.valveLatestValue = value
                this.valve = value
        }