creating eventsSince for ContactSensor and AeonKeyFobs + commenting runAfter method...
[smartthings-infrastructure.git] / ContactSensor / ContactSensor.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3 import Timer.SimulatedTimer
4
5 //JPF's Verify API
6 import gov.nasa.jpf.vm.Verify
7
8 public class ContactSensor {
9         private String id
10         private String label
11         private String displayName
12         private String contactState
13         private String currentContact   
14         private String latestValue
15         private String alarmState
16         private List events = []
17         private List timeOfEvents = []
18         
19
20         ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
21                 this.id = id
22                 this.label = label
23                 this.displayName = displayName
24                 this.contactState = contactState
25                 this.currentContact = currentContact
26                 this.latestValue = latestValue
27                 this.alarmState = alarmState
28         }
29
30         def eventsSince() {
31                 def evtOpen = [[name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
32                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
33                                [name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
34                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
35                                [name: "tamper.tampered", value: "open", deviceId: "contactSensorID0", descriptionText: "",
36                                 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
37                 def evtClosed = [[name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
38                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
39                                  [name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
40                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'],
41                                  [name: "tamper.tampered", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
42                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']]
43                 def init = Verify.getInt(0,4)
44                 def evtToSend = []
45                 if (init == 0) {//return empty set
46                         return evtToSend
47                 } else if (init == 1) {//send one open event
48                         evtOpen.each{
49                                 evtToSend.add(it)
50                         }
51                         return evtToSend
52                 } else if (init == 2) {//send two open events
53                         evtOpen.each{
54                                 evtToSend.add(it)
55                         }
56                         evtOpen.each{
57                                 evtToSend.add(it)
58                         }
59                         return evtToSend
60                 } else if (init == 3) {//send one closed event
61                         evtClosed.each{
62                                 evtToSend.add(it)
63                         }
64                         return evtToSend
65                 } else if (init == 4) {//send two closed events
66                         evtClosed.each{
67                                 evtToSend.add(it)
68                         }
69                         evtClosed.each{
70                                 evtToSend.add(it)
71                         }
72                         return evtToSend
73                 }
74         }
75
76         def setValue(String value) {
77                 println("the contact sensor with id:$id is triggered to $value!")
78                 this.contactState = value
79                 this.currentContact = value
80                 this.latestValue = value
81         }
82
83         
84         def on() {
85                 println("the contact sensor with id:$id is armed!")
86                 this.alarmState = "armed"
87         }
88
89         def off() {
90                 println("the contact sensor with id:$id is not armed!")
91                 this.alarmState = "not armed"
92         }
93         
94         def currentValue(String deviceFeature) {
95                 if (deviceFeature == "contact") {
96                         return contactState
97                 }
98         }
99
100         def currentState(String deviceFeature) {
101                 if (deviceFeature == "contact") {
102                         return contactState
103                 }
104         }
105
106         def latestValue(String deviceFeature) {
107                 if (deviceFeature == "contact") {
108                         return latestValue
109                 }
110         }
111 }