Changes in classes: new concept for latest value + all types of events generated...
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevel.groovy
index 4b7acbf9d7ce495ffb2957c7f9e33a48179e0209..ff83a50e86a0c8c51b96499b252f2aa7b4c9943b 100644 (file)
@@ -34,7 +34,7 @@ public class SwitchLevel {
                        println("the switch with id:$id is setted to level $level!")
                        this.level = level
                        this.rate = level
-                       sendEvent([name: "level", value: "50", deviceId: this.id, descriptionText: "",
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
@@ -42,11 +42,13 @@ public class SwitchLevel {
        def on() {
                if (this.switchState != "on") {
                        println("the 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"}'])
                }
        }
 
@@ -54,11 +56,13 @@ public class SwitchLevel {
                if (this.switchState != "on") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the 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"}'])
                        }
                }
        }
@@ -66,11 +70,13 @@ public class SwitchLevel {
        def off() {
                if (this.switchState != "off") {
                        println("the 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"}'])
                }
        }
 
@@ -78,11 +84,13 @@ public class SwitchLevel {
                if (this.switchState != "off") {
                        def task = timers.runAfter(metaData["delay"]) {
                                println("the 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"}'])
                        }
                }
        }