X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=SwitchLevel%2FSwitchLevel.groovy;h=7db6a168d8cecdbe1ab33404aa6ab33b1e54ec08;hb=5661e02c23e94167de4f76e3ba0eb53e2d69fc94;hp=24bd7bfa0f3b03aba3b026067cdfaa1171641297;hpb=622fbb619774231a71cb2a1dfd6df36f8f6659c9;p=smartthings-infrastructure.git diff --git a/SwitchLevel/SwitchLevel.groovy b/SwitchLevel/SwitchLevel.groovy index 24bd7bf..7db6a16 100644 --- a/SwitchLevel/SwitchLevel.groovy +++ b/SwitchLevel/SwitchLevel.groovy @@ -10,12 +10,14 @@ public class SwitchLevel { private String currentSwitch private int level private int rate + private int hue + 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 @@ -23,12 +25,35 @@ public class SwitchLevel { this.displayName = displayName this.level = level this.rate = level + this.hue = 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.rate = metaData["level"] + this.hue = 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!") @@ -38,6 +63,16 @@ public class SwitchLevel { 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.rate = 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") { @@ -47,8 +82,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 +94,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 +106,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 +118,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"}']) } } }