- this.level = level
- this.currentLevel = level
- this.rate = level
- this.currentRate = level
- this.hue = hue
- this.currentHue = hue
- this.saturation = saturation
- this.currentSaturation = saturation
- this.switchState = switchState
- this.currentSwitch = switchState
- this.switchLatestValue = switchLatestValue
- }
-
- //By Apps
- 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"]
- 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"}'])
- sendEvent([name: "hue", value: "$hue", 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
- this.currentLevel = 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"}'])
- }
- }
-
- def setLevel(long 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.currentRate = level
- sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def on() {
- if (this.switchState != "on") {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
-
- def on(LinkedHashMap metaData) {
- if (this.switchState != "on") {
- def task = timers.runAfter(metaData["delay"]) {
- println("the switch with id:$id is on!")
- this.switchLatestValue = "on"
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
- }
- }
- }