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 println("the alarm with id:$id is triggered to $value!")
30 this.alarmLatestValue = value
32 this.currentAlarm = value
38 if (alarm != "both") {
39 println("the alarm with id:$id is changed to both!")
40 this.alarmLatestValue = "both"
42 this.currentAlarm = "both"
43 sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
44 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
54 println("the alarm with id:$id is changed to off!")
55 this.alarmLatestValue = "off"
57 this.currentAlarm = "off"
58 sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
59 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
64 if (alarm != "siren") {
65 println("the alarm with id:$id is changed to siren!")
66 this.alarmLatestValue = "siren"
68 this.currentAlarm = "siren"
69 sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
70 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
75 if (alarm != "strobe") {
76 println("the alarm with id:$id is changed to strobe!")
77 this.alarmLatestValue = "strobe"
79 this.currentAlarm = "strobe"
80 sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
81 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
85 def currentValue(String deviceFeature) {
86 if (deviceFeature == "alarm") {
91 def latestValue(String deviceFeature) {
92 if (deviceFeature == "alarm") {
93 return alarmLatestValue