Commit #9: extension to the infrastructure with more devices + minor changes in extra...
[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 latestValue
11
12         ContactSensor(String id, String label, String displayName, String contactState, String latestValue) {
13                 this.id = id
14                 this.label = label
15                 this.displayName = displayName
16                 this.contactState = contactState
17                 this.latestValue = latestValue
18         }
19
20         def setValue(String value) {
21                 this.latestValue = contactState
22                 println("the contact sensor with id:$id is triggered to $value!")
23                 this.contactState = value
24         }
25         
26         def currentValue(String deviceFeature) {
27                 if (deviceFeature == "contact") {
28                         return contactState
29                 }
30         }
31
32         def latestValue(String deviceFeature) {
33                 if (deviceFeature == "contact") {
34                         return latestValue
35                 }
36         }
37 }