Commit #10: more classes
[smartthings-infrastructure.git] / PresenceSensor / PresenceSensor.groovy
1 //Create a class for presence sensor
2 package PresenceSensor
3 import Timer.SimulatedTimer
4
5 public class PresenceSensor {
6         private String id
7         private String label
8         private String displayName
9         private String presence
10         private String currentPresence
11         private String presenceLatestValue
12
13         PresenceSensor(String id, String label, String displayName, String presence, String presenceLatestValue) {
14                 this.id = id
15                 this.label = label
16                 this.displayName = displayName
17                 this.presence = presence
18                 this.currentPresence = presence
19                 this.presenceLatestValue = presenceLatestValue
20         }
21
22         def setValue(String value) {
23                 this.presenceLatestValue = presence
24                 println("the presence sensor with id:$id is triggered to $value!")
25                 this.presence = value
26                 this.currentPresence = value
27         }
28
29         
30         def currentValue(String deviceFeature) {
31                 if (deviceFeature == "presence") {
32                         return presence
33                 }
34         }
35
36         def latestValue(String deviceFeature) {
37                 if (deviceFeature == "presence") {
38                         return presenceLatestValue
39                 }
40         }
41 }