Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / RelaySwitch / RelaySwitch.groovy
index b418477477944dc7c93dd4a68af616cde5ec5bbd..137d7ad837d24533fee2d6ae95f4be1bc3c2d4ff 100644 (file)
@@ -28,11 +28,13 @@ public class RelaySwitch {
        def on() {
                if (switchState != "on") {
                        println("the relay switch with id:$id is on!")
-                       this.switchLatestValue = this.switchState
+                       this.switchLatestValue = "on"
                        this.switchState = "on"
                        this.currentSwitch = "on"
                        sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
-                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -40,11 +42,13 @@ public class RelaySwitch {
                if (switchState != "on") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the relay switch with id:$id is on!")
-                               this.switchLatestValue = this.switchState
+                               this.switchLatestValue = "on"
                                this.switchState = "on"
                                this.currentSwitch = "on"
                                sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                               sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }
@@ -52,11 +56,13 @@ public class RelaySwitch {
        def off() {
                if (switchState != "off") {
                        println("the relay switch with id:$id is off!")
-                       this.switchLatestValue = this.switchState
+                       this.switchLatestValue = "off"
                        this.switchState = "off"
                        this.currentSwitch = "off"
                        sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                       sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -64,11 +70,13 @@ public class RelaySwitch {
                if (switchState != "off") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the relay switch with id:$id is off!")
-                               this.switchLatestValue = this.switchState
+                               this.switchLatestValue = "off"
                                this.switchState = "off"
                                this.currentSwitch = "off"
                                sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                                          displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+                               sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+                                         displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        }
                }
        }
@@ -76,7 +84,7 @@ public class RelaySwitch {
        //By Model Checker
        def setValue(String value) {
                println("the relay switch with id:$id is $value!")
-               this.switchLatestValue = this.switchState
+               this.switchLatestValue = value
                this.switchState = value
                this.currentSwitch = value
        }