}
def on() {
- println("the switch with id:$id is on!")
- this.switchLatestValue = this.switchState
- this.switchState = "on"
- this.currentSwitch = "on"
- sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
- }
-
- def on(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
+ if (this.switchState != "on") {
println("the switch with id:$id is on!")
this.switchLatestValue = this.switchState
this.switchState = "on"
this.currentSwitch = "on"
sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
}
}
- def off() {
- println("the switch with id:$id is off!")
- this.switchLatestValue = this.switchState
- this.switchState = "off"
- this.currentSwitch = "off"
- sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+ def on(LinkedHashMap metaData) {
+ if (this.switchState != "on") {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the switch with id:$id is on!")
+ this.switchLatestValue = this.switchState
+ 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 off(LinkedHashMap metaData) {
- def task = timers.runAfter(metaData["delay"]) {
+ def off() {
+ if (this.switchState != "off") {
println("the switch with id:$id is off!")
this.switchLatestValue = this.switchState
this.switchState = "off"
this.currentSwitch = "off"
sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
- displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
+ }
+
+ def off(LinkedHashMap metaData) {
+ if (this.switchState != "off") {
+ def task = timers.runAfter(metaData["delay"]) {
+ println("the switch with id:$id is off!")
+ this.switchLatestValue = this.switchState
+ this.switchState = "off"
+ this.currentSwitch = "off"
+ sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+ }
}
}