1 //Create a class for alarm device
3 import Timer.SimulatedTimer
8 private String displayName
10 private String currentAlarm
11 private String alarmLatestValue
16 Alarm(Closure sendEvent, String id, String label, String displayName, String alarm, String currentAlarm, String alarmLatestValue) {
17 this.sendEvent = sendEvent
18 this.timers = new SimulatedTimer()
21 this.displayName = displayName
23 this.currentAlarm = currentAlarm
24 this.alarmLatestValue = alarmLatestValue
28 def setValue(String value) {
29 this.alarmLatestValue = alarm
30 println("the alarm with id:$id is triggered to $value!")
32 this.currentAlarm = value
38 println("the alarm with id:$id is changed to both!")
39 this.alarmLatestValue = this.alarm
41 this.currentAlarm = "both"
42 sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
43 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "both"]])
51 println("the alarm with id:$id is changed to off!")
52 this.alarmLatestValue = this.alarm
54 this.currentAlarm = "off"
55 sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
56 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
60 println("the alarm with id:$id is changed to siren!")
61 this.alarmLatestValue = this.alarm
63 this.currentAlarm = "siren"
64 sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
65 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "siren"]])
69 println("the alarm with id:$id is changed to strobe!")
70 this.alarmLatestValue = this.alarm
72 this.currentAlarm = "strobe"
73 sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
74 displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "strobe"]])
77 def currentValue(String deviceFeature) {
78 if (deviceFeature == "alarm") {
83 def latestValue(String deviceFeature) {
84 if (deviceFeature == "alarm") {
85 return alarmLatestValue