Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / ContactSensor / Contacts.groovy
1 //Create a class for contact sensor
2 package ContactSensor
3 import Timer.SimulatedTimer
4
5 public class Contacts {
6         private int id
7         private String displayName
8         private String contactState
9         private String contactLatestValue
10
11         Contacts(int id, String displayName, String contactState, String contactLatestValue) {
12                 this.id = id
13                 this.displayName = displayName
14                 this.contactState = contactState
15                 this.contactLatestValue = contactLatestValue
16         }
17
18         def setValue(String value) {
19                 this.contactLatestValue = contactState
20                 println("the contact sensor with id:$id is triggered to $value!")
21                 this.contactState = value
22         }
23         
24         def currentValue(String deviceFeature) {
25                 if (deviceFeature == "contact") {
26                         return contactState
27                 }
28         }
29
30         def latestValue(String deviceFeature) {
31                 if (deviceFeature == "contact") {
32                         return contactLatestValue
33                 }
34         }
35 }