Fixing switch level
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevel.groovy
index 7db6a168d8cecdbe1ab33404aa6ab33b1e54ec08..ea2e122b5f4a157344cd7bb98569b4f9afa2e6be 100644 (file)
@@ -8,7 +8,7 @@ public class SwitchLevel {
        private String displayName
        private String switchState
        private String currentSwitch
-       private int level
+       private int currentLevel
        private int rate
        private int hue
        private int saturation
@@ -23,7 +23,7 @@ public class SwitchLevel {
                this.id = id
                this.label = label
                this.displayName = displayName
-               this.level = level
+               this.currentLevel = level
                this.rate = level
                this.hue = hue
                this.saturation = saturation
@@ -34,8 +34,8 @@ public class SwitchLevel {
 
        //By Apps
        def setColor(LinkedHashMap metaData) {
-               if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
-                       this.level = metaData["level"]
+               if ((this.currentLevel != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
+                       this.currentLevel = metaData["level"]
                        this.rate = metaData["level"]
                        this.hue = metaData["hue"]
                        this.saturation = metaData["saturation"]
@@ -55,9 +55,9 @@ public class SwitchLevel {
        }       
 
        def setLevel(int level) {
-               if (this.level != level) {
+               if (this.currentLevel != level) {
                        println("the switch with id:$id is setted to level $level!")
-                       this.level = level
+                       this.currentLevel = level
                        this.rate = level
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -65,9 +65,9 @@ public class SwitchLevel {
        }
        
        def setLevel(long level) {
-               if (this.level != level) {
+               if (this.currentLevel != level) {
                        println("the switch with id:$id is setted to level $level!")
-                       this.level = level
+                       this.currentLevel = level
                        this.rate = level
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -131,7 +131,7 @@ public class SwitchLevel {
                        this.currentSwitch = value
                } else if (name == "level") {
                        println("the switch with id:$id is setted to level $value!")
-                       this.level = value.toInteger()
+                       this.currentLevel = value.toInteger()
                        this.rate = value.toInteger()
                }
        }
@@ -139,7 +139,7 @@ public class SwitchLevel {
 
        def currentValue(String deviceFeature) {
                if (deviceFeature == "level") {
-                       return level
+                       return currentLevel
                } else if (deviceFeature == "switch") {
                        return switchState
                }
@@ -147,7 +147,7 @@ public class SwitchLevel {
 
        def latestValue(String deviceFeature) {
                if (deviceFeature == "level") {
-                       return level
+                       return currentLevel
                } else if (deviceFeature == "switch") {
                        return switchState
                }