X-Git-Url: http://plrg.eecs.uci.edu/git/?p=smartthings-infrastructure.git;a=blobdiff_plain;f=SwitchLevel%2FSwitchLevel.groovy;h=2b5020eab7b4334234e02e550919768618d25b60;hp=8782365c322147d3d01655b98b77c51419f8e860;hb=f719b3a1011f5d99e474a4164b09e3ab528a9dfe;hpb=07922ca948668ed1b4b294d414951b4e2aec802e diff --git a/SwitchLevel/SwitchLevel.groovy b/SwitchLevel/SwitchLevel.groovy index 8782365..2b5020e 100644 --- a/SwitchLevel/SwitchLevel.groovy +++ b/SwitchLevel/SwitchLevel.groovy @@ -9,31 +9,79 @@ 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 def timers - SwitchLevel(Closure sendEvent, String id, String label, String displayName, int level, String switchState, String switchLatestValue) { + SwitchLevel(Closure sendEvent, String id, String label, String displayName, int level, int hue, int saturation, String switchState, String switchLatestValue) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.id = id 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 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"] + 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"}']) } @@ -47,8 +95,6 @@ public class SwitchLevel { this.currentSwitch = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } @@ -61,8 +107,6 @@ public class SwitchLevel { this.currentSwitch = "on" sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } } @@ -75,8 +119,6 @@ public class SwitchLevel { this.currentSwitch = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } @@ -89,8 +131,6 @@ public class SwitchLevel { this.currentSwitch = "off" sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) - sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "", - displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } } @@ -105,7 +145,26 @@ 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() + } + } + + + def currentValue(String deviceFeature) { + if (deviceFeature == "level") { + return level + } else if (deviceFeature == "switch") { + return switchState + } + } + + def latestValue(String deviceFeature) { + if (deviceFeature == "level") { + return level + } else if (deviceFeature == "switch") { + return switchState } } }