1 //Create a class for door control device
3 import Timer.SimulatedTimer
5 public class DoorControl {
8 private String displayName
9 private String doorState
10 private String doorLatestValue
15 DoorControl(Closure sendEvent, String id, String label, String displayName, String doorState, String doorLatestValue) {
16 this.sendEvent = sendEvent
17 this.timers = new SimulatedTimer()
20 this.displayName = displayName
21 this.doorState = doorState
22 this.doorLatestValue = doorLatestValue
27 if (doorState != "open") {
28 println("the door with id:$id is open!")
29 this.doorLatestValue = "open"
30 this.doorState = "open"
31 sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
32 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
33 sendEvent([name: "doorControl.open", value: "open", deviceId: this.id, descriptionText: "",
34 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
38 def open(LinkedHashMap metaData) {
39 if (doorState != "open") {
40 def task = timers.runAfter(metaData["delay"]) {
41 println("the door with id:$id is open!")
42 this.doorLatestValue = "open"
43 this.doorState = "open"
44 sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
45 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
46 sendEvent([name: "doorControl.open", value: "open", deviceId: this.id, descriptionText: "",
47 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
53 if (doorState != "closed") {
54 println("the door with id:$id is closed!")
55 this.doorLatestValue = "closed"
56 this.doorState = "closed"
57 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
58 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
59 sendEvent([name: "doorControl.closed", value: "closed", deviceId: this.id, descriptionText: "",
60 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
64 def close(LinkedHashMap metaData) {
65 if (doorState != "closed") {
66 def task = timers.runAfter(metaData["delay"]) {
67 println("the door with id:$id is closed!")
68 this.doorLatestValue = "closed"
69 this.doorState = "closed"
70 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
71 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
72 sendEvent([name: "doorControl.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 door with id:$id is $value!")
81 this.doorLatestValue = value
82 this.doorState = value
85 def currentValue(String deviceFeature) {
86 if (deviceFeature == "status") {
91 def latestValue(String deviceFeature) {
92 if (deviceFeature == "status") {
93 return doorLatestValue