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 = "open"
31 sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
32 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
33 sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
34 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
38 def open(LinkedHashMap metaData) {
39 if (valve != "open") {
40 def task = timers.runAfter(metaData["delay"]) {
41 println("the valve with id:$id is open!")
42 this.valveLatestValue = "open"
44 sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
45 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
46 sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
47 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
53 if (valve != "closed") {
54 println("the valve with id:$id is closed!")
55 this.valveLatestValue = "closed"
57 sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
58 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
59 sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
60 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
64 def close(LinkedHashMap metaData) {
65 if (valve != "closed") {
66 def task = timers.runAfter(metaData["delay"]) {
67 println("the valve with id:$id is closed!")
68 this.valveLatestValue = "closed"
70 sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
71 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
72 sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
73 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
79 def setValue(String value) {
80 println("the valve with id:$id is $value!")
81 this.valveLatestValue = value
85 def currentValue(String deviceFeature) {
86 if (deviceFeature == "valve") {
91 def latestValue(String deviceFeature) {
92 if (deviceFeature == "valve") {
93 return valveLatestValue