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