//Create a class for alarm device package Alarm import Timer.SimulatedTimer public class Alarm { private String id private String label private String displayName private String alarm private String currentAlarm private String alarmLatestValue def sendEvent def timers Alarm(Closure sendEvent, String id, String label, String displayName, String alarm, String currentAlarm, String alarmLatestValue) { this.sendEvent = sendEvent this.timers = new SimulatedTimer() this.id = id this.label = label this.displayName = displayName this.alarm = alarm this.currentAlarm = currentAlarm this.alarmLatestValue = alarmLatestValue } //By model checker def setValue(String value) { this.alarmLatestValue = alarm println("the alarm with id:$id is triggered to $value!") this.alarm = value this.currentAlarm = value } //By Apps def both() { println("the alarm with id:$id is changed to both!") this.alarmLatestValue = this.alarm this.alarm = "both" this.currentAlarm = "both" sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "both"]]) } def on() { both() } def off() { println("the alarm with id:$id is changed to off!") this.alarmLatestValue = this.alarm this.alarm = "off" this.currentAlarm = "off" sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]]) } def siren() { println("the alarm with id:$id is changed to siren!") this.alarmLatestValue = this.alarm this.alarm = "siren" this.currentAlarm = "siren" sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "siren"]]) } def strobe() { println("the alarm with id:$id is changed to strobe!") this.alarmLatestValue = this.alarm this.alarm = "strobe" this.currentAlarm = "strobe" sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "strobe"]]) } def currentValue(String deviceFeature) { if (deviceFeature == "alarm") { return currentAlarm } } def latestValue(String deviceFeature) { if (deviceFeature == "alarm") { return alarmLatestValue } } }