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
26 println("the door with id:$id is open!")
27 this.doorLatestValue = this.doorState
28 this.doorState = "open"
29 sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
30 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
33 def open(LinkedHashMap metaData) {
34 def task = timers.runAfter(metaData["delay"]) {
35 println("the door with id:$id is open!")
36 this.doorLatestValue = this.doorState
37 this.doorState = "open"
38 sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
39 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "open"]])
44 println("the door with id:$id is closed!")
45 this.doorLatestValue = this.doorState
46 this.doorState = "closed"
47 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
48 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
51 def close(LinkedHashMap metaData) {
52 def task = timers.runAfter(metaData["delay"]) {
53 println("the door with id:$id is closed!")
54 this.doorLatestValue = this.doorState
55 this.doorState = "closed"
56 sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
57 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "closed"]])
62 def setValue(String value) {
63 println("the door with id:$id is $value!")
64 this.doorLatestValue = this.doorState
65 this.doorState = value
68 def currentValue(String deviceFeature) {
69 if (deviceFeature == "status") {
74 def latestValue(String deviceFeature) {
75 if (deviceFeature == "status") {
76 return doorLatestValue