Cleaning up Extractor.groovy.
[smartthings-infrastructure.git] / ContactSensor / ContactSensor.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3 import Timer.SimulatedTimer
4
5 public class ContactSensor {
6         private String id
7         private String label
8         private String displayName
9         private String contactState
10         private String currentContact   
11         private String latestValue
12         private String alarmState
13         private List events = []
14         private List timeOfEvents = []
15         
16
17         ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
18                 this.id = id
19                 this.label = label
20                 this.displayName = displayName
21                 this.contactState = contactState
22                 this.currentContact = currentContact
23                 this.latestValue = latestValue
24                 this.alarmState = alarmState
25         }
26
27         def setValue(String value) {
28                 println("the contact sensor with id:$id is triggered to $value!")
29                 this.contactState = value
30                 this.currentContact = value
31                 this.latestValue = value
32         }
33
34         
35         def on() {
36                 println("the contact sensor with id:$id is armed!")
37                 this.alarmState = "armed"
38         }
39
40         def off() {
41                 println("the contact sensor with id:$id is not armed!")
42                 this.alarmState = "not armed"
43         }
44         
45         def currentValue(String deviceFeature) {
46                 if (deviceFeature == "contact") {
47                         return contactState
48                 }
49         }
50
51         def currentState(String deviceFeature) {
52                 if (deviceFeature == "contact") {
53                         return contactState
54                 }
55         }
56
57         def latestValue(String deviceFeature) {
58                 if (deviceFeature == "contact") {
59                         return latestValue
60                 }
61         }
62 }