Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[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         
14
15         ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
16                 this.id = id
17                 this.label = label
18                 this.displayName = displayName
19                 this.contactState = contactState
20                 this.currentContact = currentContact
21                 this.latestValue = latestValue
22                 this.alarmState = alarmState
23         }
24
25         def setValue(String value) {
26                 this.latestValue = contactState
27                 println("the contact sensor with id:$id is triggered to $value!")
28                 this.contactState = value
29                 this.currentContact = value
30         }
31         
32         def on() {
33                 println("the contact sensor with id:$id is armed!")
34                 this.alarmState = "armed"
35         }
36
37         def off() {
38                 println("the contact sensor with id:$id is not armed!")
39                 this.alarmState = "not armed"
40         }
41         
42         def currentValue(String deviceFeature) {
43                 if (deviceFeature == "contact") {
44                         return contactState
45                 }
46         }
47
48         def latestValue(String deviceFeature) {
49                 if (deviceFeature == "contact") {
50                         return latestValue
51                 }
52         }
53 }