9be6569f1dfb9677cbfdf77f87298fea07c809ee
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
1 //Create a class for alarm device
2 package Alarm
3 import Timer.SimulatedTimer
4
5 public class Alarms {
6         int deviceNumbers       
7         List alarms
8         def timers
9         def sendEvent
10
11         //If we have only one device
12         private String id = "alarmID0"
13         private String label = "alarm0"
14         private String displayName = "alarm0"
15         private String alarm = "off"
16         private String currentAlarm = "off"
17         private String alarmLatestValue = "off"
18
19         Alarms(Closure sendEvent, int deviceNumbers) {
20                 this.sendEvent = sendEvent
21                 this.timers = new SimulatedTimer()
22                 this.deviceNumbers = deviceNumbers
23                 this.alarms = []
24
25                 alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
26         }
27
28         //Methods for closures
29         def count(Closure Input) {
30                 alarms.count(Input)
31         }
32         def size() {
33                 alarms.size()
34         }
35         def each(Closure Input) {
36                 alarms.each(Input)
37         }
38         def find(Closure Input) {
39                 alarms.find(Input)
40         }
41         def collect(Closure Input) {
42                 alarms.collect(Input)
43         }
44
45         //By Apps
46         def both() {
47                 alarms[0].both()
48                 alarmLatestValue = alarm
49                 alarm = "both"
50                 currentAlarm = "both"
51         }
52
53         def off() {
54                 alarms[0].off()
55                 alarmLatestValue = alarm
56                 alarm = "off"
57                 currentAlarm = "off"
58         }
59
60         def on() {
61                 both()
62         }
63
64         def siren() {
65                 alarms[0].siren()
66                 alarmLatestValue = alarm
67                 alarm = "siren"
68                 currentAlarm = "siren"
69         }
70
71         def strobe() {
72                 alarms[0].strobe()
73                 alarmLatestValue = alarm
74                 alarm = "strobe"
75                 currentAlarm = "strobe"
76         }
77
78         def currentValue(String deviceFeature) {
79                 alarms[0].currentValue(deviceFeature)
80         }
81
82         def latestValue(String deviceFeature) {
83                 alarms[0].latestValue(deviceFeature)
84         }
85
86         def getAt(int ix) {
87                 alarms[ix]
88         }
89 }