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"}'])
45 sendEvent([name: "alarm.both", value: "both", deviceId: this.id, descriptionText: "",
46 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
56 println("the alarm with id:$id is changed to off!")
57 this.alarmLatestValue = "off"
59 this.currentAlarm = "off"
60 sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
61 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
62 sendEvent([name: "alarm.off", value: "off", deviceId: this.id, descriptionText: "",
63 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
68 if (alarm != "siren") {
69 println("the alarm with id:$id is changed to siren!")
70 this.alarmLatestValue = "siren"
72 this.currentAlarm = "siren"
73 sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
74 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
75 sendEvent([name: "alarm.siren", value: "siren", deviceId: this.id, descriptionText: "",
76 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
81 if (alarm != "strobe") {
82 println("the alarm with id:$id is changed to strobe!")
83 this.alarmLatestValue = "strobe"
85 this.currentAlarm = "strobe"
86 sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
87 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
88 sendEvent([name: "alarm.strobe", value: "strobe", deviceId: this.id, descriptionText: "",
89 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
93 def currentValue(String deviceFeature) {
94 if (deviceFeature == "alarm") {
99 def latestValue(String deviceFeature) {
100 if (deviceFeature == "alarm") {
101 return alarmLatestValue