changes in switch level class
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
index d9d2e267617a05943ffcc70f5eea37e0501cc240..773c1ccfad8e37d48107045e1b7768a2a2e2cc48 100644 (file)
@@ -13,9 +13,13 @@ 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 int currentSaturation = 70
        private String switchState = "on"
        private String currentSwitch = "on"
        private String switchLatestValue = "on"
@@ -28,17 +32,25 @@ 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.currentSaturation = 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.currentSaturation = 90
                        this.switchState = "on"
                        this.currentSwitch = "on"
                        this.switchLatestValue = "on"
@@ -70,9 +82,13 @@ 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"]
+                       this.currentSaturation = metaData["saturation"]
                        switchLevels[0].setColor(metaData)
                }
        }
@@ -86,7 +102,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 +113,8 @@ public class SwitchLevels {
                        switchLevels[0].setLevel(level)
                        this.level = level
                        this.rate = level
+                       this.currentLevel = level
+                       this.currentRate = level
                }
        }
 
@@ -143,6 +163,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)