Commit #9: More classes + Extractor with Rahmadi's editions + Fixing some bugs
[smartthings-infrastructure.git] / Alarm / Alarms.groovy
diff --git a/Alarm/Alarms.groovy b/Alarm/Alarms.groovy
new file mode 100644 (file)
index 0000000..9be6569
--- /dev/null
@@ -0,0 +1,89 @@
+//Create a class for alarm device
+package Alarm
+import Timer.SimulatedTimer
+
+public class Alarms {
+       int deviceNumbers       
+       List alarms
+       def timers
+       def sendEvent
+
+       //If we have only one device
+       private String id = "alarmID0"
+       private String label = "alarm0"
+       private String displayName = "alarm0"
+       private String alarm = "off"
+       private String currentAlarm = "off"
+       private String alarmLatestValue = "off"
+
+       Alarms(Closure sendEvent, int deviceNumbers) {
+               this.sendEvent = sendEvent
+               this.timers = new SimulatedTimer()
+               this.deviceNumbers = deviceNumbers
+               this.alarms = []
+
+               alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
+       }
+
+       //Methods for closures
+       def count(Closure Input) {
+               alarms.count(Input)
+       }
+       def size() {
+               alarms.size()
+       }
+       def each(Closure Input) {
+               alarms.each(Input)
+       }
+       def find(Closure Input) {
+               alarms.find(Input)
+       }
+       def collect(Closure Input) {
+               alarms.collect(Input)
+       }
+
+       //By Apps
+       def both() {
+               alarms[0].both()
+               alarmLatestValue = alarm
+               alarm = "both"
+               currentAlarm = "both"
+       }
+
+       def off() {
+               alarms[0].off()
+               alarmLatestValue = alarm
+               alarm = "off"
+               currentAlarm = "off"
+       }
+
+       def on() {
+               both()
+       }
+
+       def siren() {
+               alarms[0].siren()
+               alarmLatestValue = alarm
+               alarm = "siren"
+               currentAlarm = "siren"
+       }
+
+       def strobe() {
+               alarms[0].strobe()
+               alarmLatestValue = alarm
+               alarm = "strobe"
+               currentAlarm = "strobe"
+       }
+
+       def currentValue(String deviceFeature) {
+               alarms[0].currentValue(deviceFeature)
+       }
+
+       def latestValue(String deviceFeature) {
+               alarms[0].latestValue(deviceFeature)
+       }
+
+       def getAt(int ix) {
+               alarms[ix]
+       }
+}