Infrastructure that works for all the locks' group!
[smartthings-infrastructure.git] / DoorControl / DoorControl.groovy
index 4317849a30982993fd4c1d53fcf7092934f77d0f..1830070772ab0260773d1cde53eb24cdc915166a 100644 (file)
@@ -23,38 +23,46 @@ public class DoorControl {
 
        //By Apps
        def open() {
-               println("the door with id:$id is open!")
-               this.doorLatestValue = this.doorState
-               this.doorState = "open"
-               sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
-       }
-
-       def open(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+               if (doorState != "open") {
                        println("the door with id:$id is open!")
                        this.doorLatestValue = this.doorState
                        this.doorState = "open"
                        sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def close() {
-               println("the door with id:$id is closed!")
-               this.doorLatestValue = this.doorState
-               this.doorState = "closed"
-               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                   displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
+       def open(LinkedHashMap metaData) {
+               if (doorState != "open") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is open!")
+                               this.doorLatestValue = this.doorState
+                               this.doorState = "open"
+                               sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
+               }
        }
 
-       def close(LinkedHashMap metaData) {
-               def task = timers.runAfter(metaData["delay"]) {
+       def close() {
+               if (doorState != "closed") {
                        println("the door with id:$id is closed!")
                        this.doorLatestValue = this.doorState
                        this.doorState = "closed"
                        sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
-                           displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
+       def close(LinkedHashMap metaData) {
+               if (doorState != "closed") {
+                       def task = timers.runAfter(metaData["delay"]) {
+                               println("the door with id:$id is closed!")
+                               this.doorLatestValue = this.doorState
+                               this.doorState = "closed"
+                               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
                }
        }