changes in switch level class
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevel.groovy
index 32ae59116dc5cc18cbb2d2d8d133b5700e8fe77e..ac7895733f874a70fe2af93a47784c10d2e39c68 100644 (file)
@@ -9,9 +9,13 @@ public class SwitchLevel {
        private String switchState
        private String currentSwitch
        private int level
        private String switchState
        private String currentSwitch
        private int level
+       private int currentLevel
        private int rate
        private int rate
+       private int currentRate
        private int hue
        private int hue
+       private int currentHue
        private int saturation
        private int saturation
+       private int currentSaturation
        private String switchLatestValue
        def sendEvent   
        def timers
        private String switchLatestValue
        def sendEvent   
        def timers
@@ -24,9 +28,13 @@ public class SwitchLevel {
                this.label = label
                this.displayName = displayName
                this.level = level
                this.label = label
                this.displayName = displayName
                this.level = level
+               this.currentLevel = level
                this.rate = level
                this.rate = level
+               this.currentRate = level
                this.hue = hue
                this.hue = hue
+               this.currentHue = hue
                this.saturation = saturation
                this.saturation = saturation
+               this.currentSaturation = saturation
                this.switchState = switchState
                this.currentSwitch = switchState
                this.switchLatestValue = switchLatestValue
                this.switchState = switchState
                this.currentSwitch = switchState
                this.switchLatestValue = switchLatestValue
@@ -36,9 +44,13 @@ public class SwitchLevel {
        def setColor(LinkedHashMap metaData) {
                if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
                        this.level = metaData["level"]
        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.rate = metaData["level"]
+                       this.currentRate = metaData["level"]
                        this.hue = metaData["hue"]
                        this.hue = metaData["hue"]
+                       this.currentHue = metaData["hue"]
                        this.saturation = metaData["saturation"]
                        this.saturation = metaData["saturation"]
+                       this.currentSaturation = metaData["saturation"]
                        println("the switch with id:$id is setted to level $level and hue to $hue and saturation to $saturation!")
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                        println("the switch with id:$id is setted to level $level and hue to $hue and saturation to $saturation!")
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -47,13 +59,20 @@ public class SwitchLevel {
                        sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
                        sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
+       }
+
+       def setLevel(String level) {
+               def newLevel = level.toInteger()
+               setLevel(newLevel)
        }       
 
        def setLevel(int level) {
                if (this.level != level) {
                        println("the switch with id:$id is setted to level $level!")
                        this.level = level
        }       
 
        def setLevel(int level) {
                if (this.level != level) {
                        println("the switch with id:$id is setted to level $level!")
                        this.level = level
+                       this.currentLevel = level
                        this.rate = level
                        this.rate = level
+                       this.currentRate = level
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
@@ -63,7 +82,9 @@ public class SwitchLevel {
                if (this.level != level) {
                        println("the switch with id:$id is setted to level $level!")
                        this.level = level
                if (this.level != level) {
                        println("the switch with id:$id is setted to level $level!")
                        this.level = level
+                       this.currentLevel = level
                        this.rate = level
                        this.rate = level
+                       this.currentRate = level
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
                        sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
@@ -127,7 +148,9 @@ public class SwitchLevel {
                } else if (name == "level") {
                        println("the switch with id:$id is setted to level $value!")
                        this.level = value.toInteger()
                } 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()
                        this.rate = value.toInteger()
+                       this.currentRate = value.toInteger()
                }
        }
 
                }
        }