Integrating List of constant names into the if-statement to avoid creating read/write...
[smartthings-infrastructure.git] / ImageCapture / ImageCapture.groovy
1 //Create a class for image capture sensor
2 package ImageCapture
3 import Timer.SimulatedTimer
4
5 public class ImageCapture {
6         private String id
7         private String label
8         private String displayName
9         private String image
10         private String alarmState
11         def timers
12
13         ImageCapture(String id, String label, String displayName, String image, String alarmState) {
14                 this.id = id
15                 this.label = label
16                 this.displayName = displayName
17                 this.image = image
18                 this.alarmState = alarmState
19                 this.timers = new SimulatedTimer()
20         }
21         
22         def alarmOn() {
23                 if (alarmState != "armed") {
24                         println("The camera with id:$id is armed!")
25                         this.alarmState = "armed"
26                 }
27         }
28
29         def alarmOff() {
30                 if (alarmState != "not armed") {
31                         println("The camera with id:$id is not armed!")
32                         this.alarmState = "not armed"
33                 }
34         }
35
36         def take() {
37                 println("The camera with id:$id is taken a picture!")
38         }
39
40         def take(LinkedHashMap metaData) {
41                 def task = timers.runAfter(metaData["delay"]) {
42                         println("The camera with id:$id is taken a picture!")
43                 }
44         }
45 }