//Create a class for alarm device package Alarm import SmartThing.SmartThing public class Alarm extends SmartThing { // id, label, and display name of the device StringBuilder id = new StringBuilder() StringBuilder label = new StringBuilder() StringBuilder displayName = new StringBuilder() // Features with string values StringBuilder currentAlarm = new StringBuilder() // Maps from features to values HashMap deviceValuesMap = new HashMap() Alarm(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, StringBuilder currentAlarm) { deviceValuesMap = deviceValueSmartThing idSmartThing = id labelSmartThing = label displayNameSmartThing = displayName sendEventSmartThings = sendEvent // Initialization this.id = id this.label = label this.displayName = displayName this.currentAlarm = currentAlarm deviceValuesMap.put("alarm", currentAlarm) } // Methods to set values def both() { action("both") } def on() { action("both") } def off() { action("off") } def siren() { action("siren") } def strobe() { action("strobe") } def action(String newValue) { if (!currentAlarm.equals(newValue)) { String tmpID = id.toString() currentAlarm.replace(0, currentAlarm.length(), newValue) println("the alarm with id:$tmpID is changed to $newValue!") sendEvent([name: "alarm", value: newValue, deviceId: tmpID, descriptionText: "", displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}']) } } // Methods to return values def getCurrentAlarm() { return currentAlarm.toString() } }