1 //Create a class for valve
3 import Timer.SimulatedTimer
8 private String displayName
10 private String valveLatestValue
15 Valve(Closure sendEvent, String id, String label, String displayName, String valve, String valveLatestValue) {
16 this.sendEvent = sendEvent
17 this.timers = new SimulatedTimer()
20 this.displayName = displayName
22 this.valveLatestValue = valveLatestValue
27 if (valve != "open") {
28 println("the valve with id:$id is open!")
29 this.valveLatestValue = this.valve
31 sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
32 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
36 def open(LinkedHashMap metaData) {
37 if (valve != "open") {
38 def task = timers.runAfter(metaData["delay"]) {
39 println("the valve with id:$id is open!")
40 this.valveLatestValue = this.valve
42 sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
43 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
49 if (valve != "closed") {
50 println("the valve with id:$id is closed!")
51 this.valveLatestValue = this.valve
53 sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
54 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
58 def close(LinkedHashMap metaData) {
59 if (valve != "closed") {
60 def task = timers.runAfter(metaData["delay"]) {
61 println("the valve with id:$id is closed!")
62 this.valveLatestValue = this.valve
64 sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
65 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
71 def setValue(String value) {
72 println("the valve with id:$id is $value!")
73 this.valveLatestValue = this.valve
77 def currentValue(String deviceFeature) {
78 if (deviceFeature == "valve") {
83 def latestValue(String deviceFeature) {
84 if (deviceFeature == "valve") {
85 return valveLatestValue