Make a change in switchLevel class to make its variable specific with variables in...
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
index d9d2e26..bc9140c 100644 (file)
@@ -13,8 +13,11 @@ public class SwitchLevels {
        private String label = "switchLevel0"
        private String displayName = "switchLevel0"
        private int level = 50
+       private int currentLevel = 50
        private int rate = 50
+       private int currentRate = 50
        private int hue = 30
+       private int currentHue = 30
        private int saturation = 70
        private String switchState = "on"
        private String currentSwitch = "on"
@@ -28,16 +31,22 @@ public class SwitchLevels {
 
                if (init) {
                        this.level = 50
+                       this.currentLevel = 50
                        this.rate = 50
+                       this.currentRate = 50
                        this.hue = 30
+                       this.currentHue = 30
                        this.saturation = 70
                        this.switchState = "off"
                        this.currentSwitch = "off"
                        this.switchLatestValue = "off"
                } else {
                        this.level = 60
+                       this.currentLevel = 60
                        this.rate = 60
+                       this.currentRate = 60
                        this.hue = 50
+                       this.currentHue = 50
                        this.saturation = 90
                        this.switchState = "on"
                        this.currentSwitch = "on"
@@ -70,8 +79,11 @@ public class SwitchLevels {
        def setColor(LinkedHashMap metaData) {
                if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
                        this.level = metaData["level"]
+                       this.currentLevel = metaData["level"]
                        this.rate = metaData["level"]
+                       this.currentRate = metaData["level"]
                        this.hue = metaData["hue"]
+                       this.currentHue = metaData["hue"]
                        this.saturation = metaData["saturation"]
                        switchLevels[0].setColor(metaData)
                }
@@ -86,7 +98,9 @@ public class SwitchLevels {
                if (this.level != level) {
                        switchLevels[0].setLevel(level)
                        this.level = level
+                       this.currentLevel = level
                        this.rate = level
+                       this.currentRate = level
                }
        }
        
@@ -95,6 +109,8 @@ public class SwitchLevels {
                        switchLevels[0].setLevel(level)
                        this.level = level
                        this.rate = level
+                       this.currentLevel = level
+                       this.currentRate = level
                }
        }
 
@@ -143,6 +159,8 @@ public class SwitchLevels {
                } else if (eventDataMap["name"] == "level") {
                        if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
                                this.level = eventDataMap["value"].toInteger()
+                               this.currentLevel = eventDataMap["value"].toInteger()
+                               this.currentRate = eventDataMap["value"].toInteger()
                                this.rate = eventDataMap["value"].toInteger()
                                switchLevels[0].setValue(eventDataMap["value"], "level")
                                sendEvent(eventDataMap)