From f719b3a1011f5d99e474a4164b09e3ab528a9dfe Mon Sep 17 00:00:00 2001 From: amiraj Date: Fri, 15 Nov 2019 14:32:50 -0800 Subject: [PATCH] Make a change in switchLevel class to make its variable specific with variables in the programs! --- SwitchLevel/SwitchLevel.groovy | 15 +++++++++++++++ SwitchLevel/SwitchLevels.groovy | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/SwitchLevel/SwitchLevel.groovy b/SwitchLevel/SwitchLevel.groovy index 7db6a16..2b5020e 100644 --- a/SwitchLevel/SwitchLevel.groovy +++ b/SwitchLevel/SwitchLevel.groovy @@ -9,8 +9,11 @@ public class SwitchLevel { private String switchState private String currentSwitch private int level + private int currentLevel private int rate + private int currentRate private int hue + private int currentHue private int saturation private String switchLatestValue def sendEvent @@ -24,8 +27,11 @@ public class SwitchLevel { this.label = label this.displayName = displayName this.level = level + this.currentLevel = level this.rate = level + this.currentRate = level this.hue = hue + this.currentHue = hue this.saturation = saturation this.switchState = switchState this.currentSwitch = switchState @@ -36,8 +42,11 @@ public class SwitchLevel { 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"] 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: "", @@ -58,7 +67,9 @@ public class SwitchLevel { 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"}']) } @@ -68,7 +79,9 @@ public class SwitchLevel { 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"}']) } @@ -132,7 +145,9 @@ public class SwitchLevel { } 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.currentRate = value.toInteger() } } diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy index d9d2e26..bc9140c 100644 --- a/SwitchLevel/SwitchLevels.groovy +++ b/SwitchLevel/SwitchLevels.groovy @@ -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) -- 2.34.1