Adding commands in run.sh.
[smartthings-infrastructure.git] / DoorControl / DoorControl.groovy
index 4317849a30982993fd4c1d53fcf7092934f77d0f..c82587925e93dc58d473a03114673bd0e6ef2119 100644 (file)
@@ -19,49 +19,58 @@ public class DoorControl {
                this.label = label
                this.displayName = displayName
                this.doorState = doorState
+               this.doorLatestValue = doorLatestValue
        }
 
        //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.doorLatestValue = "open"
                        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 = "open"
+                               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.doorLatestValue = "closed"
                        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 = "closed"
+                               this.doorState = "closed"
+                               sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
+                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       }
                }
        }
 
        //By Model Checker
        def setValue(String value) {
                println("the door with id:$id is $value!")
-               this.doorLatestValue = this.doorState
+               this.doorLatestValue = value
                this.doorState = value
        }