Fixing path in the script.
[smartthings-infrastructure.git] / Switch / Switch.groovy
index d01d27be361b5268d7b8dcc1e7a21ec44e8cd748..8bea530901861fb341c8d998f554748785d58e4e 100644 (file)
@@ -28,14 +28,18 @@ public class Switch {
 
        //By Apps
        def setLevel(int level) {
-               println("the switch with id:$id is setted to level $level!")
-               this.currentLevel = level
+               if (this.currentLevel != level) {
+                       println("the switch with id:$id is setted to level $level!")
+                       this.currentLevel = level
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        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: "",
@@ -47,7 +51,7 @@ public class Switch {
                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: "",
@@ -59,7 +63,7 @@ public class Switch {
        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: "",
@@ -71,7 +75,7 @@ public class Switch {
                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: "",
@@ -83,7 +87,7 @@ public class Switch {
        //By Model Checker
        def setValue(String value) {
                println("the switch with id:$id is $value!")
-               this.switchLatestValue = this.switchState
+               this.switchLatestValue = value
                this.switchState = value
                this.currentSwitch = value
        }