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"}'])
36 def open(LinkedHashMap metaData) {
37 if (doorState != "open") {
38 def task = timers.runAfter(metaData["delay"]) {
39 println("the door with id:$id is open!")
40 this.doorLatestValue = "open"
41 this.doorState = "open"
42 sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
43 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
49 if (doorState != "closed") {
50 println("the door with id:$id is closed!")
51 this.doorLatestValue = "closed"
52 this.doorState = "closed"
53 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
54 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
58 def close(LinkedHashMap metaData) {
59 if (doorState != "closed") {
60 def task = timers.runAfter(metaData["delay"]) {
61 println("the door with id:$id is closed!")
62 this.doorLatestValue = "closed"
63 this.doorState = "closed"
64 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
65 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
71 def setValue(String value) {
72 println("the door with id:$id is $value!")
73 this.doorLatestValue = value
74 this.doorState = value
77 def currentValue(String deviceFeature) {
78 if (deviceFeature == "status") {
83 def latestValue(String deviceFeature) {
84 if (deviceFeature == "status") {
85 return doorLatestValue