1 //Create a class for alarm device
3 import Timer.SimulatedTimer
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"
19 Alarms(Closure sendEvent, int deviceNumbers, boolean init) {
20 this.sendEvent = sendEvent
21 this.timers = new SimulatedTimer()
22 this.deviceNumbers = deviceNumbers
27 this.currentAlarm = "off"
28 this.alarmLatestValue = "off"
31 this.currentAlarm = "on"
32 this.alarmLatestValue = "on"
34 alarms.add(new Alarm(sendEvent, id, label, displayName, this.alarm, this.currentAlarm, this.alarmLatestValue))
38 def setValue(LinkedHashMap eventDataMap) {
39 if (eventDataMap["value"] != alarms[0].alarm) {
40 this.alarmLatestValue = eventDataMap["value"]
41 this.alarm = eventDataMap["value"]
42 this.currentAlarm = eventDataMap["value"]
43 alarms[0].setValue(eventDataMap["value"])
44 sendEvent(eventDataMap)
48 //Methods for closures
49 def count(Closure Input) {
55 def each(Closure Input) {
58 def find(Closure Input) {
61 def sort(Closure Input) {
64 def collect(Closure Input) {
70 if (alarm != "both") {
71 alarmLatestValue = "both"
80 alarmLatestValue = "off"
92 if (alarm != "siren") {
93 alarmLatestValue = "siren"
95 currentAlarm = "siren"
101 if (alarm != "strobe") {
102 alarmLatestValue = "strobe"
104 currentAlarm = "strobe"
109 def currentValue(String deviceFeature) {
110 alarms[0].currentValue(deviceFeature)
113 def latestValue(String deviceFeature) {
114 alarms[0].latestValue(deviceFeature)