Fixing path in the script.
[smartthings-infrastructure.git] / Switch / Switch.groovy
index b924d21d3ec3af148d91211fc041ad8db1c57253..8bea530901861fb341c8d998f554748785d58e4e 100644 (file)
@@ -31,7 +31,7 @@ public class Switch {
                if (this.currentLevel != level) {
                        println("the switch with id:$id is setted to level $level!")
                        this.currentLevel = level
-                       sendEvent([name: "level", value: "40", deviceId: this.id, descriptionText: "",
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
@@ -39,7 +39,7 @@ public class Switch {
        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: "",
@@ -51,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: "",
@@ -63,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: "",
@@ -75,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: "",
@@ -87,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
        }