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